using UnityEngine; using System.Collections; using System.Collections.Generic; namespace Kit { public class Hack { public static void DestroyAllChild(GameObject _obj, bool _immediate) { Kit.Hack.DestroyAllChild(_obj.transform, _immediate); } public static void DestroyAllChild(Transform _transform, bool _immediate) { List<GameObject> _children=new List<GameObject>(); foreach(Transform _child in _transform) _children.Add(_child.gameObject); _children.ForEach(delegate(GameObject obj) { if( _immediate ) MonoBehaviour.DestroyImmediate(obj); else MonoBehaviour.Destroy(obj); }); } } }
經常要 destroy child 寫一段自用的 kit.