- Home /
Question by
av123 · Jun 10, 2017 at 07:51 AM ·
c#coroutinescounterupdate function2 player
count how many times a player has played
Hello, i am trying to create a game with two players and each of them will play three times in a row and then they will switch. The players have both the same script and i have created a playermanager script to control who will play. When i press '1' player 1 is playing and when i press '2' player2. The thing is that i want automatically in the start of the game, player 1 to play for 3 times and after that player 2 for 3 more times. My code is :
if (Input.GetKeyDown("1"))
{
if (player2.enabled == true)
{
player2.enabled = false;
player1.enabled = true;
}
else
{
player1.enabled = true;
player2.enabled = false;
}
}
if (Input.GetKeyDown("2"))
{
if (player1.enabled == true)
{
player1.enabled = false;
player2.enabled = true;
}
else
{
player2.enabled = true;
player2.enabled = false;
}
}
The problem is that wherever i try to count, the counters aren't working properly as the Update function is constantly called and when i take off the key pressed thing nothing happens because of that too. Any new ideas? Thanks in advance
Comment