playMaker

Author Topic: DestroyChildren  (Read 1554 times)

Zyxil

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
DestroyChildren
« on: August 28, 2012, 06:36:46 PM »
Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Destroy all children on the Game Object.")]
    public class DestroyChildren : FsmStateAction
    {
        [RequiredField]
        public FsmOwnerDefault gameObject;

        public override void Reset()
        {
            gameObject = null;
        }

        public override void OnEnter()
        {
            DoDestroyChildren(Fsm.GetOwnerDefaultTarget(gameObject));

            Finish();
        }

        static void DoDestroyChildren(GameObject go)
        {
            if (go != null)
            {
                for (int i = 0; i < go.transform.GetChildCount(); i++)
                    GameObject.Destroy(go.transform.GetChild(0).gameObject);
            }
        }
    }
}
« Last Edit: August 28, 2012, 06:59:27 PM by Zyxil »