unity通过脚本获取一个物体的所有子物体孙子物体,并从里面找到有动画的物体

发布时间:2019-05-20编辑:佚名阅读(2474)

public Transform[] grandFa;
    public List<GameObject> animObs = new List<GameObject>();
    public int indexAnim = 0;
    // Use this for initialization  
    void Start()
    {
        grandFa = GetComponentsInChildren<Transform>();//打到所有的子孙子物体
 
        //get all objects of having animator, that is there is no child
        foreach (Transform child in grandFa)
        {//找到最下一层的子节点,以及子节点上有动画的物体
            if (child.childCount == 0 && child.gameObject.GetComponent<Animator>())
            {
                animObs.Add(child.gameObject);
                child.gameObject.GetComponent<Animator>().enabled = false;
            }
        }
    }


  关键字:unity脚本获取子物体孙子物体动画


鼓掌

2

正能量

1

0

呵呵

0


评论区