Unity3d有序获取所有子物体

来源:互联网 发布:网络统考成绩查询时间 编辑:程序博客网 时间:2024/05/17 18:13
<span style="font-size:18px;">for (int i = 0; i < gameObject.transform.childCount; i++)            {                if (</span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 18px;">gameObject</span><span style="font-family: Arial, Helvetica, sans-serif;">.transform.GetChild(i).gameObject.GetComponent<>().)</span><span style="font-size:18px;">                {                    gameObject.transform.GetChild(i).gameObject.GetComponent<>().;                }            }</span>
</pre><pre name="code" class="csharp">获取然后删除
for (int i = tr.childCount - 1; i >= 0; i--) {       Destroy(tr.GetChild(i).gameObject);}

或者存到一个列表里

List lst = new List;foreach (Transform child in transform){    lst.Add(child);     Debug.Log(child.gameObject.name);}

以上就是获取子物体的一些方法,非常简单

0 0
原创粉丝点击