Get children gameobjects array and assign the script inside

Get children gameobjects array

Get references to all gameobjects that are tagged with a particular tag?

Sort an ArrayList of game objects

...

GameObject assetBundle = GameObject.FindGameObjectWithTag("main");    //找到parent gameobject
Transform[] parts = assetBundle.GetComponentsInChildren<Transform>();  //找到所有含有Transform Component的集合,这里不能写<GameObject>
foreach (Transform part in parts)
  {
    if (part.tag == "main")
      continue;
    if (part.gameObject.GetComponent("TearApartControl"))    //通过<Transform>找到每一个chile gameobject
      continue;
    part.gameObject.AddComponent("TearApartControl");    //为每一个child gameobject附上相同的script
  }

...

 

posted @ 2013-01-29 06:38  若愚Shawn  阅读(185)  评论(0编辑  收藏  举报