I am making a turn-based strategy game like Civilization. The solution for the turns I found is that I have a ‘turnDone’ variable on all my units. It is false by default, but after a step it turns true.
I also have a script that is supposed to access this value from all the Units that are currently in the game.
void Update(){
GameObject[] playerUnits = GameObject.FindGameObjectsWithTag ("Player");
foreach (GameObject playerunit in playerUnits) {
if( playerunit.GetComponent<Unit>().turnDone){
playerunit.GetComponent<Unit>().turnDone = false;
}
}
}
My problem is that it looks at all the scripts individually i.e. if one unit’s turnDone is true, this script will turn all the units’ turnDone false.
Is there a solution to access all the scripts’ turnDone values collectively so that it would only turn them false if all the units’ turnDone is true?