HasExitedCollision.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks
  3. {
  4. [TaskDescription("Returns success when a collision ends. 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 HasExitedCollision : Conditional
  7. {
  8. [Tooltip("The tag of the GameObject to check for a collision against")]
  9. public SharedString tag = "";
  10. [Tooltip("The object that exited the collision")]
  11. public SharedGameObject collidedGameObject;
  12. private bool exitedCollision = false;
  13. public override TaskStatus OnUpdate()
  14. {
  15. return exitedCollision ? TaskStatus.Success : TaskStatus.Failure;
  16. }
  17. public override void OnEnd()
  18. {
  19. exitedCollision = false;
  20. }
  21. public override void OnCollisionExit(Collision collision)
  22. {
  23. if (string.IsNullOrEmpty(tag.Value) || tag.Value.Equals(collision.gameObject.tag)) {
  24. collidedGameObject.Value = collision.gameObject;
  25. exitedCollision = true;
  26. }
  27. }
  28. public override void OnReset()
  29. {
  30. collidedGameObject = null;
  31. }
  32. }
  33. }