| 12345678910111213141516171819202122232425262728293031323334 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace EnemyAI
- {
- internal class ChaseBehavior : Behavior
- {
- internal override Result Run(ref Blackboard blackboard)
- {
- blackboard.navMeshAgent.isStopped = false;
- if (!blackboard.Night)
- {
- blackboard.navMeshAgent.isStopped = true;
- return Result.Failure;
- }
- if (Vector3.Distance(blackboard.PlayerPosition, blackboard.EnemyPosition) < 0.5f)
- {
- //Close enough to player
- return Result.Success;
- }
- //If the player moved so far that re-pathing is necessary
- if (Vector3.Distance(blackboard.PlayerPosition, blackboard.navMeshAgent.destination) > 0.5f)
- {
- blackboard.navMeshAgent.destination = blackboard.PlayerPosition;
- }
- return Result.Running;
- }
- }
- }
|