Пример #1
0
    private void StateMachineRunningPerFrame()
    {
        BasicMeleeState nextState = BasicMeleeState.Idle;

        if (currentState == BasicMeleeState.Meet)
        {
            // Check if aggro
            if (!IsPlayerInMeetRange())
            {
                nextState = BasicMeleeState.Idle;
            }
            else if (IsPlayerInAggroRange())
            {
                nextState = BasicMeleeState.Aggro;
            }
            else
            {
                nextState = BasicMeleeState.Meet;
            }
        }
        else if (currentState == BasicMeleeState.Aggro)
        {
            if (!IsPlayerInMeetRange())
            {
                nextState = BasicMeleeState.Idle;
            }
            else if (IsPlayerInAttackRange() && canAttack)
            {
                nextState = BasicMeleeState.Attack;
            }
            else
            {
                nextState = BasicMeleeState.Aggro;
            }
        }
        else if (currentState == BasicMeleeState.Attack)
        {
            if (attackTimeCounter >= attckTimeFrame)
            {
                canAttack = false;
                if (IsPlayerInAttackRange())
                {
                    playerHealth.DealDamage(attackDamage);
                }
                attackTimeCounter = 0;
                attacksfx.Play();
                nextState = BasicMeleeState.Aggro;
            }
            else
            {
                attackTimeCounter++;
                nextState = BasicMeleeState.Attack;
            }
        }
        else if (currentState == BasicMeleeState.Death)
        {
            if (stateCounter >= deathFrame)
            {
                nextState = BasicMeleeState.Death;
                monsterHealth.Die();
            }
            else
            {
                stateCounter++;
                nextState = BasicMeleeState.Death;
            }
        }
        else if (currentState == BasicMeleeState.Hurt)
        {
            if (stateCounter >= hurtFrame)
            {
                nextState = BasicMeleeState.Meet;
            }
            else
            {
                stateCounter++;
                nextState = BasicMeleeState.Hurt;
            }
        }
        else
        {
            // Check if meet
            if (IsPlayerInMeetRange())
            {
                nextState = BasicMeleeState.Meet;
            }
            else
            {
                nextState = BasicMeleeState.Idle;
            }
        }
        if (currentState != BasicMeleeState.Hurt && monsterHealth.IsHurt && currentState != BasicMeleeState.Death)
        {
            nextState = BasicMeleeState.Hurt;
        }
        if (currentState != BasicMeleeState.Death && monsterHealth.IsDie)
        {
            nextState = BasicMeleeState.Death;
        }
        if (nextState != currentState)
        {
            changeState(nextState);
        }
    }
Пример #2
0
 private void StateMachineRunningPerFrame()
 {
     BasicRangeState nextState = BasicRangeState.Idle;
     if (currentState == BasicRangeState.Meet)
     {
         if (canAttack)
         {
             LinearBullet spawned = Instantiate<LinearBullet>(linearBullet);
             spawned.Setup(transform.position, player.transform.position, bulletVelocity, damage);
             canAttack = false;
         }
         if (!IsPlayerInMeetRange()) nextState = BasicRangeState.Idle;
         else if (IsPlayerInEscapeRange()) nextState = BasicRangeState.Escape;
         else nextState = BasicRangeState.Meet;
     }
     else if (currentState == BasicRangeState.Escape)
     {
         if (!IsPlayerInMeetRange()) nextState = BasicRangeState.Idle;
         else if (!IsPlayerInEscapeRange()) nextState = BasicRangeState.Meet;
         else nextState = BasicRangeState.Escape;
     }
     else if (currentState == BasicRangeState.Death)
     {
         if (stateCounter >= deathFrame)
         {
             nextState = BasicRangeState.Death;
             monsterHealth.Die();
         }
         else
         {
             stateCounter++;
             nextState = BasicRangeState.Death;
         }
     }
     else if (currentState == BasicRangeState.Hurt)
     {
         if (stateCounter >= hurtFrame)
         {
             nextState = BasicRangeState.Meet;
         }
         else
         {
             stateCounter++;
             nextState = BasicRangeState.Hurt;
         }
     }
     else
     {
         // Check if meet
         if (IsPlayerInMeetRange()) nextState = BasicRangeState.Meet;
         else nextState = BasicRangeState.Idle;
     }
     if (currentState != BasicRangeState.Hurt && monsterHealth.IsHurt)
     {
         nextState = BasicRangeState.Hurt;
     }
     if (currentState != BasicRangeState.Death && monsterHealth.IsDie)
     {
         nextState = BasicRangeState.Death;
     }
     if(nextState != currentState) changeState(nextState);
 }
Пример #3
0
    private void StateMachineRunningPerFrame()
    {
        SlowDebuffState nextState = SlowDebuffState.Idle;

        if (currentState == SlowDebuffState.Meet)
        {
            //spriteRenderer.color = Color.red;
            if (canAttack)
            {
                ProjectileMovement spawned = Instantiate <ProjectileMovement>(projectileBullet);
                spawned.Setup(transform.position, player.transform.position, 0.1f);
                canAttack = false;
            }
            if (!IsPlayerInMeetRange())
            {
                nextState = SlowDebuffState.Idle;
            }
            else if (IsPlayerInEscapeRange())
            {
                nextState = SlowDebuffState.Escape;
            }
            else
            {
                nextState = SlowDebuffState.Meet;
            }
        }
        else if (currentState == SlowDebuffState.Escape)
        {
            //spriteRenderer.color = Color.cyan;
            if (!IsPlayerInMeetRange())
            {
                nextState = SlowDebuffState.Idle;
            }
            else if (!IsPlayerInEscapeRange())
            {
                nextState = SlowDebuffState.Meet;
            }
            else
            {
                nextState = SlowDebuffState.Escape;
            }
        }
        else if (currentState == SlowDebuffState.Death)
        {
            if (stateCounter >= deathFrame)
            {
                nextState = SlowDebuffState.Death;
                monsterHealth.Die();
            }
            else
            {
                stateCounter++;
                nextState = SlowDebuffState.Death;
            }
        }
        else if (currentState == SlowDebuffState.Hurt)
        {
            if (stateCounter >= hurtFrame)
            {
                nextState = SlowDebuffState.Meet;
            }
            else
            {
                stateCounter++;
                nextState = SlowDebuffState.Hurt;
            }
        }
        else
        {
            // Check if meet
            if (IsPlayerInMeetRange())
            {
                nextState = SlowDebuffState.Meet;
            }
            else
            {
                nextState = SlowDebuffState.Idle;
            }
        }
        if (currentState != SlowDebuffState.Hurt && monsterHealth.IsHurt)
        {
            nextState = SlowDebuffState.Hurt;
        }
        if (currentState != SlowDebuffState.Death && monsterHealth.IsDie)
        {
            nextState = SlowDebuffState.Death;
        }
        if (nextState != currentState)
        {
            changeState(nextState);
        }
    }