public void Shoot() { if (canShoot) { enemyAttack?.Attack(); } }
private void FixedUpdate() { // If the player is detected then the enemy starts to follow the player if (playerDetected && !agent.isStopped) { bool isAttacking = enemyAttack.GetIsAttacking(); // If the player is outside the stoppingDistance then make the enemy follow the player if (distance > attackRadius) { if (!isAttacking) { // Make the eneny follow the player destination = player.position; agent.SetDestination(destination); character.Move(agent.desiredVelocity, false); } } else { bool tryingToAttack = enemyAttack.GetTryingToAttack(); if (!isAttacking && !tryingToAttack) { agent.SetDestination(transform.position); // When the enemy is inside attackRadius the enemy can attack enemyAttack.Attack(player, transform, attackRadius); } if (tryingToAttack) { // Make the eneny follow the player destination = player.position; agent.SetDestination(destination); agent.stoppingDistance = 1.5f; character.Move(agent.desiredVelocity, false); } else { character.Move(Vector3.zero, false); } } // Check if the player is at the enemy's back float distEnemyPlayer = transform.position.x - player.position.x; // If the player is at its back then make it turn around Quaternion newRotation = new Quaternion(); if (distEnemyPlayer >= 0) { newRotation = Quaternion.Lerp(rb.rotation, Quaternion.Euler(0f, -90f, 0f), turnSmoothing * Time.deltaTime); } else if (distEnemyPlayer < 0) { newRotation = Quaternion.Lerp(rb.rotation, Quaternion.Euler(0f, 90f, 0f), turnSmoothing * Time.deltaTime); } rb.MoveRotation(newRotation); } }
void Attack() { enemyAttack.Attack(); Invoke("FinishAttack", enemyAttack.GetAttackDelay()); state = State.WaitAttackFinish; }
private void Attack() { _enemyAttackBehaviour?.Attack(); }