unity3d 遍历gameobjectstag 随机实例化一个对象_遍历所有的洞
void RandomPig(){
GameObject[] holeObjs = GameObject.FindGameObjectsWithTag("Hole");
int i=Random.Range(0,holeObjs.Length);
Object clonePig=Instantiate(pigObj,new Vector3(holeObjs.transform.position.x-0.9f,holeObjs.transform.position.y,2.1f),holeObjs.transform.rotation);
GameObject [] pigObjs=GameObject.FindGameObjectsWithTag("Pig");
int j=Random.Range(0,i);
if(pigObjs.Length<=2)
{
Object clonePig1=Instantiate(pigObj,new Vector3(holeObjs.transform.position.x-0.9f,holeObjs.transform.position.y,2.1f),holeObjs.transform.rotation);
}
}随机实例化总场景不超过二个猪的二个猪 不错,小代码精悍 强烈支持楼主ing……{:5_427:} 支持,新手学习了 好东西 好东西 顶顶 楼主是超人 好帖就是要顶 真心顶 说的非常好 很好哦
页:
[1]