获取父类
当前对象是子物体Sphere,获取层级列表上一级父物体Cube:
GameObject sphere;
GameObject parentOfSphere;
void Start()
{
sphere = GameObject.Find("Sphere");
parentOfSphere = sphere.transform.parent.gameObject;
Debug.Log(parentOfSphere.name);
}
获取子物体
- 当前物体是父物体Cube,获取子物体Capsule
GameObject Cube;
void Start()
{
Cube = GameObject.Find("Cube");
GameObject Second_childOfCube = Cube.transform.GetChild(1).gameObject;
Debug.Log("Second_childOfCube " + Second_childOfCube.name);
}
- 当前物体是子物体Sphere,获取子物体Capsule
GameObject sphere;
void Start()
{
sphere = GameObject.Find("Sphere");
GameObject SameLayer_OfSphere = sphere.transform.parent.GetChild(1).gameObject;
Debug.Log("SameLayer_OfSphere " + SameLayer_OfSphere.name);
}
撒花~~加油!!!干文章
|