using System.Collections; using System.Collections.Generic; using UnityEngine; public class SetFalse : MonoBehaviour { public Transform[] hiddenChildren; [ContextMenu("隐藏")] // Start is called before the first frame update void Setttt() { HideChildrenRecursively(transform, false); } [ContextMenu("显示")] // Start is called before the first frame update void SetTrue() { HideChildrenRecursively(transform,true); } void Start() { } void HideChildrenRecursively(Transform parent,bool ist) { foreach (Transform child in parent) { // 隐藏当前子物体 child.gameObject.SetActive(ist); // 递归调用以处理子物体的子物体 HideChildrenRecursively(child, ist); } } }