public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.IsInTransition(layerIndex)) { return; } _target = _brain.GetCurrentTarget(); if (_target is null) { return; } // See if we can use our special attack if (_combat.CanUseSpecialAttack) { _combat.SpecialAttack(); return; } float distance = Vector3.Distance(animator.transform.position, _target.position); // Try to attack player if they are close enough if (distance <= _brain.attackRadius) { // See if we need to rotate towards the player float angle = Vector3.SignedAngle(_target.position - animator.transform.position, animator.transform.forward, Vector3.up); if (Mathf.Abs(angle) > angleFromTargetTolerance) { animator.SetTrigger(angle < 0 ? "RotateLeft" : "RotateRight"); return; } if (!_combat.IsCoolingDown) { // Go to attack state _combat.ChooseAttack(); return; } } // Move to target player if necessary if (distance > _agent.stoppingDistance) { animator.SetTrigger("Follow"); } }