void CheckForStateChange() { switch (_state) { case STATE.FREE: { if (Input.GetKey(KeyCode.Q)) { _state = STATE.BLOCK; } else if (Input.GetKeyDown(KeyCode.C)) { _state = STATE.ROLL; } else if (Input.GetMouseButtonDown(0)) { _state = STATE.ATTACK; currentAtkPhase = ATK_PHASE.ATK_START; } break; } case STATE.ATTACK: { break; } case STATE.ROLL: { break; } case STATE.BLOCK: { if (Input.GetKeyUp(KeyCode.Q)) { _state = STATE.FREE; } break; } default: break; } }
void AttackSubstateMachine() { switch (currentAtkPhase) { case ATK_PHASE.ATK_START: { // Starts the attack attackCurrentTime = 0; // Decides the type of attack Enemy enemyBackstabbed = _attackHitbox.BackstabbedEnemy(); int attackToPlay = -1; if (enemyBackstabbed) // If an enemy is being backstabbed, perform backstab attack { attackToPlay = 0; currentAttack = ATK_TYPE.ATK_BACKSTAB; transform.position = enemyBackstabbed.transform.position - enemyBackstabbed.transform.forward * 0.5f; _attackHitbox.KillEnemy(enemyBackstabbed, attacks[attackToPlay].hitTime); } else // Otherwise perform normal soft attack { attackToPlay = 1; currentAttack = ATK_TYPE.ATK_SOFT; attackMove = move; _attackHitbox.HitAllEnemies(attacks[attackToPlay].hitTime); } currentAttackTimeSeconds = attacks[attackToPlay].animationTime; tpc.GetFullBodyAnimator().Play(attacks[attackToPlay].animationName); Invoke("EnableActions", attacks[attackToPlay].animationTime + 0.5f); currentAtkPhase = ATK_PHASE.ATK_ANIM; break; } case ATK_PHASE.ATK_ANIM: { switch (currentAttack) { case ATK_TYPE.ATK_SOFT: SoftAttacking(); break; case ATK_TYPE.ATK_BACKSTAB: BackStabbing(); break; default: break; } // Update time attackCurrentTime += Time.deltaTime; if (attackCurrentTime >= currentAttackTimeSeconds) { currentAtkPhase = ATK_PHASE.ATK_END; } break; } case ATK_PHASE.ATK_END: { attackCurrentTime = 0; _state = STATE.FREE; break; } default: break; } }