public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex) { if (navAgent == null) { navAgent = animator.GetComponent <NavMeshAgent>(); } if (target == null) { target = PlayerExample.GetInstance(); } //Reset path upon entering chase state so we have a fresh one towards the target navAgent.ResetPath(); navAgent.speed = runSpeed; }
//Check if we are within chase range of the target, is static to be used by other states public static bool ShouldChasePlayer(Vector3 _chaserPosition) { PlayerExample player = PlayerExample.GetInstance(); return((player.transform.position - _chaserPosition).sqrMagnitude < chaseRadius * chaseRadius); }