1.获取物体
方法一:GameObject node = GameObject.Find("节点名字")//若无重名
方法二:public GameObject wingNode;//全局定义,然后在unity界面获取物体(推荐)
2.获取父级
Transform parent = this.transform.parent;//获取父级的Transform
GameObject parentNode = this.transform.parent.gameObject;//获取父级的节点,GameObject充当容器的作用。
3.获取子物体
//方法一
foreeach (Transform child in transform)
{
Debug.Log("子物体:"+child.name);
}
//方法二 获取第一个子物体
Transform child = this.transform.GetChild(0);
//方法三
Transform child = this.transform.Find("子节点路径");
4.物体的操作
1.设置新的父级:
this.transform.SetParent("新父节点名称");
this.transform.setPaarent(null);//表示没有父节点,一级节点
2.设置节点的显示与隐藏
Transform child = this.transform.Find("aa");
if(child.gameObject.activeSelf){
child.gameObject.SetActive(false);
}
else{
chlid.gameObject.SetActive(true);
}