试试这个: public void DisableChildren() { foreach (Transform child in transform) { child.gameObject.SetActiveRecursively(false); } } JS 版本(如果需要的话) function DisableChildren() { for (var child : Transform in transform) { child.gameObject.SetActiveRecursively(false); } }
//假设父级是父游戏对象 for(int i=0; i< parent.transform.childCount; i++) { var child = parent.transform.GetChild(i).gameObject; if(child != null) child.setActive(false); }
试试这个:
JS 版本(如果需要的话)