Attack! Attack!
Now that the player has committed themselves into the fray, we can play through their selected action.
The attack phase will simply run for 1 second and then it will be the enemies' turn. To accomplish this, we use a simple coroutine to perform the attack itself. So, let's add the following function to the BattleManager
script:
IEnumerator AttackTarget(){ attacking=true; selectedTarget.EnemyProfile.health-=GetComponent<Attack>().hitAmount; yield return new WaitForSeconds(1); attacking=false; GetComponent<Attack>().hitAmount=0; battleStateManager.SetBool("PlayerReady", false); }
The following is what the preceding code is doing:
Sets a variable that states the player is attacking.
Decreases the selected enemy's health based on the chosen attack.
Waits for 1 second to reset the values.
Changes over to the next state.
All that is left is to call this function now when the Player_Attack
state is begun...