コード例 #1
0
ファイル: Enemy.cs プロジェクト: earneszm/AdVentures
 public void Shoot()
 {
     if (canShoot)
     {
         enemyAttack?.Attack();
     }
 }
コード例 #2
0
    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);
        }
    }
コード例 #3
0
 void Attack()
 {
     enemyAttack.Attack();
     Invoke("FinishAttack", enemyAttack.GetAttackDelay());
     state = State.WaitAttackFinish;
 }
コード例 #4
0
 private void Attack()
 {
     _enemyAttackBehaviour?.Attack();
 }