一个递归查找组件的脚本
void Start()
{
Debug.Log(FindTF(transform, "Cube (7)"));
}
public Transform FindTF(Transform parent, string name)
{
Transform TF = parent.Find(name);
if (TF != null)
return TF;
for (int i = 0; i < parent.childCount; i++)
{
TF = FindTF(parent.GetChild(i), name);
if (TF != null)
return TF;
}
return null;
}

浙公网安备 33010602011771号