I have a method ProcessTurn() that is called in Update(). If enemyTurn = true, then ProcessTurn() starts the coroutine OnEnemyAction().
OnEnemyAction() loops through each enemy in the array enemyParty, then prints the name of that enemy to console. Then it waits 2 seconds before printing the next name.
The problem is: I only want enemyTurn = false when the coroutine has finished printing the very LAST name in the array. But instead it makes enemyTurn = false as soon as the coroutine is started.
Where do I put enemyTurn = false?
void ProcessTurn()
{
if(enemyTurn)
{
StartCoroutine(OnEnemyAction());
enemyTurn = false;
}
}
IEnumerator OnEnemyAction()
{
foreach(GameObject enemy in enemyParty)
{
Debug.Log(enemy.name);
yield return new WaitForSeconds(2);
}
}