Beispiel #1
0
    void FixedUpdate()
    {
        if (Alive())
        {
            PlayerNearby = LookForPlayer();
            if (!Patrol && !PlayerNearby && !(activeState is IdleState))
            {
                SetState(new IdleState());
            }
            else if (Patrol && !PlayerNearby && !(activeState is PatrolState))
            {
                SetState(new PatrolState());
            }
            else if (PlayerNearby && !IsPlayerReachable() && !(activeState is HideState))
            {
                SetState(new HideState());
            }
            else if (PlayerMeleeRange() && !(activeState is MeleeAttackState))
            {
                SetState(new MeleeAttackState());
            }
            else if (PlayerNearby && !PlayerMeleeRange() && IsPlayerReachable() && !(activeState is ChaseState))
            {
                SetState(new ChaseState());
            }

            activeState.Act();
        }
        if (!Alive() && !triggeredDeath)
        {
            triggeredDeath = true;
            AgentAnimator.SetTrigger("Death");
        }
    }
Beispiel #2
0
 private void Jump()
 {
     if ((onGround))  //if the player presses space and we aren't already jumping or falling
     {
         onGround = false;
         AgentRigidbody.AddForce(new Vector2(0, jumpSpeed));    // make the player character jump (i.e apply a positive force on the y axis)
         AgentAnimator.SetTrigger("Jump");                      // Trigger the jump animation
     }
 }
Beispiel #3
0
 protected override void TakeDamage(int hp)
 {
     if (!Alive())
     {
         AgentAnimator.SetTrigger("Death");
         return;
     }
     base.TakeDamage(hp);
     Immunity = true;
 }