遍历存储所有物体添加到列表中(使用GameObject.activeSelf进行判断)

//存储菜单列表
List<GameObject> subMenu = new List<GameObject>();

//存储所有子菜单
public void StoreSubMenuData()
{
  var menu = mainMenuScreen.transform.FindChild("back/menuPanel");
  foreach (Transform kk in menu)
  {
    if (kk.GetComponent<Image>() != null && kk.GetComponent<Button>() == null)
    {
      subMenu.Add(kk.gameObject);
    }
  }
}
//隐藏所有子菜单
public void HideSubMenu()
{
  foreach (GameObject obj in subMenu)
  {
    if (obj.activeSelf == true)
    {
      obj.SetActive(false);
    }
  }
}

posted @ 2017-08-02 20:12  U3DEngineer  阅读(327)  评论(0编辑  收藏  举报