【发布时间】:2016-08-10 19:43:40
【问题描述】:
是否可以从 Parent 获取游戏对象 Nested Child ?
地图游戏对象如下:
ListProcess (ListProcessItem1) => item1 => 1 => ItemIcon
例如我正在使用此代码:
itemslot = GameObject.FindGameObjectWithTag ("ListProcessItem1").gameObject;
GameObject item = itemslot.gameObject.transform.GetChild(0).gameObject;
GameObject child = item.gameObject.transform.GetChild(0).gameObject;
GameObject sitemImage = child.gameObject.transform.GetChild(0).gameObject;
当我运行代码时出现错误:
UnityException: Transform child out of bounds
LakeMainProcess.generatePrize1 () (at Assets/script/fishing/LakeMainProcess.cs:48)
LakeMainProcess.Start () (at Assets/script/fishing/LakeMainProcess.cs:21)
注意: 我只能到达游戏对象(1)。游戏对象 ( ItemIcon ) 出错了。
我该如何解决?
【问题讨论】: