HasEnteredTrigger2D.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks
  3. {
  4. [TaskDescription("Returns success when an object enters the 2D trigger. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
  5. [TaskCategory("Physics")]
  6. public class HasEnteredTrigger2D : Conditional
  7. {
  8. [Tooltip("The tag of the GameObject to check for a trigger against")]
  9. public SharedString tag = "";
  10. [Tooltip("The object that entered the trigger")]
  11. public SharedGameObject otherGameObject;
  12. private bool enteredTrigger = false;
  13. public override TaskStatus OnUpdate()
  14. {
  15. return enteredTrigger ? TaskStatus.Success : TaskStatus.Failure;
  16. }
  17. public override void OnEnd()
  18. {
  19. enteredTrigger = false;
  20. }
  21. public override void OnTriggerEnter2D(Collider2D other)
  22. {
  23. if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(other.gameObject.tag)) {
  24. otherGameObject.Value = other.gameObject;
  25. enteredTrigger = true;
  26. }
  27. }
  28. public override void OnReset()
  29. {
  30. tag = "";
  31. otherGameObject = null;
  32. }
  33. }
  34. }