与常识不同,unity中获得父子节点需要通过transform。即先获得父/子节点的transform,然后再通过父/子节点的transform获得父/子节点。
获得父节点gameObject:
GameObject parentGameObject=transform.parent.gameObject;
获得子节点gameObject:
foreach (Transform child in transform) {
GameObject childGameObject=child.gameObject;
...
}
参考:http://www.360doc.com/content/14/0414/14/12282510_368791938.shtml
时间: 2024-11-01 04:44:51