using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class TransformHelpers
{
public static Transform DeepFind(this Transform TF, string childName)
{
Transform x = TF.Find(childName);//查找名字为childName的子物体
if (x != null)
{
return x;
}
if (TF.childCount == 0)
{
return null;
}
for (int i = 0; i < TF.childCount; i++)
{
Transform childTF = TF.GetChild(i);
x = DeepFind(childTF, childName);
if (x != null)
{
return x;
}
}
return null;
}
}
由上所示,复制完脚本直接调用 transform.DeepFind(Name) 就可以找到了!