Ejemplo n.º 1
0
    void Updating()
    {
        //aim enemy sword/projectile at player and attack

        if (!startedAttack)
        {
            enemy.PlaySound(enemy.enemyAudio, enemy.attackSound);
            startedAttack = true;
            enemy.Attack();
        }

        if (enemy.GetRigidBody().velocity.magnitude >= 0 && enemy.GetRigidBody().velocity.magnitude <= 0.1f)
        {
            endedAttack = true;
        }


        //TRANSITIONS GO HERE
        if ((enemy.PlayerInFieldOfView() || enemy.PlayerDetected()) && !enemy.PlayerIsWithinStrikingDistance() && (endedAttack || (enemy.GetRigidBody().velocity.magnitude >= 0 && enemy.GetRigidBody().velocity.magnitude <= 0.1f)))
        {
            startedAttack = false;
            endedAttack   = false;
            enemy.ResetAnimatorBools(enemy.anim);
            enemy.anim.SetBool("chase", true);
            ToChaseState();
        }
        else if (enemy.PlayerInFieldOfView() && enemy.PlayerIsWithinStrikingDistance() && (endedAttack || (enemy.GetRigidBody().velocity.magnitude >= 0 && enemy.GetRigidBody().velocity.magnitude <= 0.1f)))
        {
            startedAttack = false;
            endedAttack   = false;
            enemy.ResetAnimatorBools(enemy.anim);
            enemy.anim.SetBool("engarde", true);
            ToEngardeState();
        }
        else
        {
            startedAttack = false;
            endedAttack   = false;
            enemy.ResetAnimatorBools(enemy.anim);
            enemy.anim.SetBool("patrol", true);
            ToPatrolState();
        }
    }