Creating a CurrentTurn variable
I'm making a turn-based tactics game with ~6 units per side who all have different stats and world positions. Ideally I'd like there to be a single currentTurn or currentUnit gameObject reference variable, pointing to the unit whose turn it is. This way there can be a single central "what a turn looks like for anyone" script walking you through your actions. Possibly as an abstract so I could override with weird types of turns (for instance if a delayed explosion gets put into the turn order to go off at x location in y time from now, it won't do anything but explode on its "turn"). My confusion is just the grammar: How do I declare the unit who's up next to the "currentUnit" variable?
For my logic I've got: I want things counting down to 0 time, and when they hit 0 (with a tiebreaker of whoever got to a given time value first, if 2+ units hit 0 at the same time) it's their turn.
public void WhoseTurn()
{
bool turnManaged = false;
while (turnManaged == false)
{
for (int i = 0; i < initList.Count; i++)
{
if (initList[i].initValue == 0 && initList[i].tiebreaker == 0)
{
turnManaged = true;
currentUnit = initList[i];
}
}
if (turnManaged == false)
{
for (int i = 0; i < initList.Count; i++)
{
initList[i].initValue--;
initList[i].initButton.position.x -= initUnit;
}
}
}
}
(An "initUnit" is just a % of the width of the initiative bar so it sizes properly with the screen) I tried declaring currentUnit as just GameObject, but that won't take stuff like initValue - probably because it's too broad? Do I need to make a script that describes Unit as a scriptableObject or class first? If I have that, is it just,
public Unit player1 = new Unit();
or something like that?
Answer by xxmariofer · Aug 30, 2019 at 06:49 AM
i would do soemthing like this
public enum PlayerEnum
{
Player1,
Player2
}
public PlayerEnum currentPlayer;
so when comparing you can simply do
if(currentPlayer == PlayerEnum.Player1)
{
//DO YOUR STUFF
}
else
{
//DO YOUR STUFF
}
Your answer
Follow this Question
Related Questions
Why can't "int y = 0" be a statement? 0 Answers
CS1023 An embedded statement may not be a declaration or labeled statement help 1 Answer
How to declare a list of arrays? 1 Answer
NetworkBroadcastResult.broadcastData having trouble converting byte array to string 0 Answers
How To Add A Delay When Touched 0 Answers