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 ...
Get Mastering Unity 2D Game Development - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.