Unity:创建了一个自定义的找子物体的脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TransformHelper : MonoBehaviour
{
    //在层级未知的时候查找子物体
    //
    public static Transform GetChild(Transform parentTF,string childName)
    {
        Transform childTF= parentTF.Find(childName);
        if(childTF!=null)
            return childTF;
        int count=parentTF.childCount;
        for(int i=0;i<count;i++){
            childTF=GetChild(parentTF.GetChild(i),childName);
            if(childTF!=null)
                return childTF;
        }
        return null;
    }
}

 

posted @ 2020-06-14 22:08  Faker_fan  阅读(209)  评论(0编辑  收藏  举报