using System.Collections; using System.Collections.Generic; using UnityEngine; public class wuniusj : MonoBehaviour { Transform[] allChildren; // Start is called before the first frame update void Start() { Transform[] allChildren = GetComponentsInChildren(); } public void yingchang() { // 遍历并打印每个子物体的名称 foreach (Transform child in allChildren) { if (child != transform) // 排除当前物体本身 { child.gameObject.SetActive(false); } } } public void show() { yingchang(); // 遍历并打印每个子物体的名称 foreach (Transform child in allChildren) { if (child != transform) // 排除当前物体本身 { if (Random.Range(0,10) > 5) { child.gameObject.SetActive(true); } } } } // Update is called once per frame void Update() { } }