Reputation: 21
I'm creating a script for a turn-based battle system.
private void OnMouseDown()
{
if(inBattle == true && battleStart == true)
{
if (renderer.tag == "Player" && isStunned == true)
{
print(renderer.transform.name + " is stunned!");
alreadyChosen = true;
}
if (renderer.tag == "Player" && alreadyChosen == false && isPlayerTurn == true && isStunned == false)
{
print(renderer.transform.name);
characterChosen = true;
alreadyChosen = true;
}
else if (renderer.tag == "Player" && characterChosen == true)
{
print("Thanks");
characterChosen = false;
alreadyChosen = true;
actionsMade++;
}
if (renderer.tag == "Enemy" && characterChosen == true)
{
print("Hit!");
characterChosen = false;
actionsMade++;
}
if (actionsMade >= 3)
{
isPlayerTurn = false;
alreadyChosen = false;
actionsMade = 0;
}
}
}
After all 3 party members take their actions, both isPlayerTurn and actionsMade reset across all instances. However, alreadyChosen only resets on one instance, or sometimes not at all. The two that work are static variables, but alreadyChosen isn't. If I do make it static, then it would make the player only able to make one action total. I tried putting the alreadyChosen variable elsewhere, and that didn't work. Please help.
Upvotes: 2
Views: 19