// FixedUpdate is called once per frame void FixedUpdate() { // Walk Animation SetIsWalking(canWalk); if ((!Player.GetInstanceControl().IsInvisible() && FOVDetection.InFOV(transform, Player.GetArmatureTransform(), maxAngle, lookRadius)) || alertedBefore) { AlertEnemy(); // Stopping agent from moving canWalk = false; agent.ResetPath(); // Enemy looks to the player SetIsAiming(true); Vector3 direction = (Player.GetArmatureTransform().position - transform.position).normalized; Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, direction.y, direction.z)); FaceTarget(lookRotation); gun.SetShootingDirection(direction); if (!wasInFOV) { StopAllCoroutines(); StartCoroutine(shootingBehaviour); } wasInFOV = true; } else if (wasInFOV) { //If the player isn't in the enemy FOV, the enemy continues its path canWalk = true; wasInFOV = false; SetIsAiming(false); SetAgentNewDestination(); StopCoroutine(shootingBehaviour); } if (canWalk && Vector3.Distance(enemyTargetPositions[currentTargetPosition], transform.position) <= stoppingDistanceError && agent.remainingDistance == 0) { canWalk = false; StartCoroutine(WaitOnPosition()); } }