Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Using a coroutine to increment a for loop?

$
0
0
So I'm making a strategy game where the player will take their turn, then each enemy unit will go one by one, then the player's turn will start again. Right now what happens is it will cause all units to go at the same time, however if you move the i++ to within the coroutine it causes my computer to freeze. public void turnCycle() { //Player clicks a button, which starts the public function. isPlayerTurn = false; //make it so the player cannot move their units until the enemy turn is over for (int i = 0; i <= enemyTurnOrder.Count - 1;) { enemyTurnOrder[i].isMyTurn = true; //allow this unit to take it's turn enemyTurnOrder[i].turn(); //start this unit's turn CheckBool(i); //Start coroutine, checking to see if this unit has run out of movement/actions (see below) i++; //do this until for loop is done } isPlayerTurn = true; //start player's turn foreach (Unit unit in map.unitS) //when everyone is done, give all units on the field their actions back { unit.refillStanima(); } } IEnumerator CheckBool(int i) //coroutine { while (enemyTurnOrder[i].remainingMovement != 0 && enemyTurnOrder[i].standardAction != false) //are you out of spaces and actions to take? { yield return null; } enemyTurnOrder[i].isMyTurn = false; }

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>