ChaseBehavior.cs 985 B

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace EnemyAI
  5. {
  6. internal class ChaseBehavior : Behavior
  7. {
  8. internal override Result Run(ref Blackboard blackboard)
  9. {
  10. blackboard.navMeshAgent.isStopped = false;
  11. if (!blackboard.Night)
  12. {
  13. blackboard.navMeshAgent.isStopped = true;
  14. return Result.Failure;
  15. }
  16. if (Vector3.Distance(blackboard.PlayerPosition, blackboard.EnemyPosition) < 0.5f)
  17. {
  18. //Close enough to player
  19. return Result.Success;
  20. }
  21. //If the player moved so far that re-pathing is necessary
  22. if (Vector3.Distance(blackboard.PlayerPosition, blackboard.navMeshAgent.destination) > 0.5f)
  23. {
  24. blackboard.navMeshAgent.destination = blackboard.PlayerPosition;
  25. }
  26. return Result.Running;
  27. }
  28. }
  29. }