📜  Unity搜索父对象的所有子对象 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:13.938000             🧑  作者: Mango

代码示例1
using System.Collections.Generic;

private List listOfChildren;
private void GetChildRecursive(GameObject obj){
    if (null == obj)
        return;

    foreach (Transform child in obj.transform){
        if (null == child)
            continue;
        //child.gameobject contains the current child you can do whatever you want like add it to an array
        listOfChildren.Add(child.gameObject);
        GetChildRecursive(child.gameObject);
    }
}