一个递归查找组件的脚本

 

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;


}

posted @ 2021-04-13 15:39  真的勇士  阅读(50)  评论(0)    收藏  举报