【发布时间】:2018-12-12 00:44:43
【问题描述】:
我正在做一个项目,我想在按下按钮“Q”时创建一个加电效果,我有动画工作和角色,我还有我想要生成的播放器周围的生成对象(见下图) 我的问题是如何在每块岩石(产卵对象)上添加不同的重力。
这是我目前正在使用的脚本。
/* Public Variables Declaration */
public Transform spawn_LocationForSmall;
public Transform spawn_LocationForMedium;
public Transform spawn_LocationForLarge;
public GameObject smallRock_Prefab;
public GameObject mediumRock_Prefab;
public GameObject largeRock_Prefab;
/* Private Variables Declaration */
private GameObject[] smallRocks_List;
private float posX, posY, posZ;
private bool smallCount = false;
private bool mediumCount = false;
private bool largeCount = false;
private bool small_CheckPos = false;
private bool medium_CheckPos = false;
private bool large_CheckPos = false;
void Start() {
//smallRocks_List = GameObject.FindGameObjectsWithTag("smallRock");
Create_Small_Rocks();
Create_Medium_Rocks();
Create_Large_Rocks();
}
private void Create_Small_Rocks(){
for(int i=0; i<=20; i++){
small_CheckPos = false;
posX = this.transform.position.x + Random.Range(-3.0f, 3.0f);
posY = this.transform.position.y + Random.Range(-3.0f, 3.0f);
posZ = this.transform.position.z + Random.Range(-3.0f, 3.0f);
if(posX > 3f && posY > 3f){
small_CheckPos = true;
}
if (small_CheckPos == true) {
Vector3 newPos = new Vector3(posX, posY, posZ);
GameObject createdObject = GameObject.Instantiate(smallRock_Prefab,
newPos, spawn_LocationForSmall.rotation) as GameObject;
createdObject.transform.parent = spawn_LocationForSmall.transform;
}
}
smallCount = true;
}
/* the other two functions are similar to this */
【问题讨论】:
-
注意:要检查标签是否适合您的问题,您可以点击标签read the description,然后点击“更多信息”。
-
为什么每块岩石需要不同的重力?
-
实际上,岩石的重力并不比其他岩石大,但它们的质量确实更大,但您可以更改
-
@LoizosVasileiou 是的,在刚体上改变它的质量,无论是在预制件中还是通过代码。
标签: c# unity3d random rigid-bodies