Linecast.cs 946 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityPhysics2D
  3. {
  4. [TaskCategory("Unity/Physics2D")]
  5. [TaskDescription("Returns success if there is any collider intersecting the line between start and end")]
  6. public class Linecast : Action
  7. {
  8. [Tooltip("The starting position of the linecast.")]
  9. public SharedVector2 startPosition;
  10. [Tooltip("The ending position of the linecast.")]
  11. public SharedVector2 endPosition;
  12. [Tooltip("Selectively ignore colliders.")]
  13. public LayerMask layerMask = -1;
  14. public override TaskStatus OnUpdate()
  15. {
  16. return Physics2D.Linecast(startPosition.Value, endPosition.Value, layerMask) ? TaskStatus.Success : TaskStatus.Failure;
  17. }
  18. public override void OnReset()
  19. {
  20. startPosition = Vector2.zero;
  21. endPosition = Vector2.zero;
  22. layerMask = -1;
  23. }
  24. }
  25. }