Game Development Reference
In-Depth Information
Attack! Attack!
Now that the player has committed themselves into the fray, we can play through their se-
lected action. For now, this is just a single action, but if you have more characters/moves,
then this could be extended further.
As the attack is a loop that is played until the player (or his party) runs out of attacks, we
use a simple coroutine to perform the attack itself. So, let's add the following function to
the BattleManager script:
IEnumerator AttackTarget()
{
int Attacks = 0;
attacking = true;
bool attackComplete = false;
while (!attackComplete)
{
GameState.currentPlayer.Attack(selectedTarget.EnemyProfile);
selectedTarget.UpdateAI();
Attacks++;
if (selectedTarget.EnemyProfile.Health < 1 || Attacks >
GameState.currentPlayer.NoOfAttacks)
{
attackComplete = true;
}
yield return new WaitForSeconds(1);
}
}
The following is what the previous code is doing:
1. It sets the initial states for the battle. It tells us how many attacks have been per-
formed, the fact that we are attacking (disable non-attacking code such as the
GUI), and that the attack has not yet finished.
2. Then, until we are finished, we keep attacking:
◦ We call the Attack function for the player against the selected enemy
(this was defined in the Entity class; all the attacks are standard, so if
Search WWH ::




Custom Search