コード例 #1
0
 private void changeState(SlowDebuffState nextState)
 {
     if (nextState == SlowDebuffState.Meet)
     {
         fleeController.IsEnable = false;
     }
     else if (nextState == SlowDebuffState.Escape)
     {
         fleeController.IsEnable = true;
         animator.Play("debuff move");
     }
     else if (nextState == SlowDebuffState.Death)
     {
         fleeController.IsEnable = false;
         stateCounter            = 0;
         animator.Play("dead");
     }
     else if (nextState == SlowDebuffState.Hurt)
     {
         fleeController.IsEnable = false;
         stateCounter            = 0;
         attackCooldownCounter   = 0;
         animator.Play("hurt");
     }
     else
     {
         fleeController.IsEnable = false;
         animator.Play("debuff idle");
     }
     currentState = nextState;
 }
コード例 #2
0
 // Start is called before the first frame update
 void Start()
 {
     currentState       = SlowDebuffState.Idle;
     player             = GameObject.FindGameObjectWithTag("Player");
     playerGridPosition = player.GetComponent <GridPosition>();
     playerHealth       = player.GetComponent <PlayerHealth>();
     gridPosition       = GetComponent <GridPosition>();
     aStar = GetComponent <AIPath>();
     attackCooldownCounter = 0;
     attackTimeCounter     = 0;
     canAttack             = false;
     spriteRenderer        = GetComponent <SpriteRenderer>();
     fleeController        = GetComponent <EnemyFleeController>();
     animator      = GetComponentInChildren <Animator>();
     monsterHealth = GetComponent <MonsterHealth>();
     stateCounter  = 0;
 }
コード例 #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);
        }
    }