I’m trying to come up with a way to pause a script execution until certain conditions are met on another script. Here’s the code that I want to pause until that certain event and continue after it is completed.
void CalculateTurnOrder () {
units = GameObject.FindGameObjectsWithTag ("Unit").OrderByDescending(go => go.GetComponent<Stats>().speed).ToArray();
for (int i = 0; i < units.Length; i++) {
if (i+1 < units.Length) {
if (units *.GetComponent<Stats> ().friendFoe == "Friendly") {*
_ units .GetComponent ().SelectUnit ();_
* }*
_ if (units .GetComponent ().speed - units [i+1].GetComponent ().speed >= units [i+1].GetComponent ().speed) {
* i–;
}
}
}
}
The idea is that each unit has a Speed stat, which determines their turn order. What I need is for the iteration, the script itself maybe to stop until the unit, the GameObject you call SelectUnit() on, completes whatever actions it can. THEN the script resumes and most likely gives the next unit in line a move (or move twice if the speed of the i unit is at least twice as big as the i+1 unit).
So how do I make this script wait for a condition like
(!units*.GetComponent<PlayerMoveUnit> ().IsSelected)
_