Destroy.cs 968 B

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject
  3. {
  4. [TaskCategory("Unity/GameObject")]
  5. [TaskDescription("Destorys the specified GameObject. Returns Success.")]
  6. public class Destroy : Action
  7. {
  8. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  9. public SharedGameObject targetGameObject;
  10. [Tooltip("Time to destroy the GameObject in")]
  11. public float time;
  12. public override TaskStatus OnUpdate()
  13. {
  14. var destroyGameObject = GetDefaultGameObject(targetGameObject.Value);
  15. if (time == 0) {
  16. GameObject.Destroy(destroyGameObject);
  17. } else {
  18. GameObject.Destroy(destroyGameObject, time);
  19. }
  20. return TaskStatus.Success;
  21. }
  22. public override void OnReset()
  23. {
  24. targetGameObject = null;
  25. time = 0;
  26. }
  27. }
  28. }