- Home /
Counting players by trigger Problem
Hello, I'm trying to make "waiting spawn area" where every new player (joining by PUN) will be detected by OnTriggerEnter, i have a float countOfWaitingPlayers and every time the new player joins i'm adding 1, when that number of players in this area will be = to float = maxPlayersOnArena it will activate GameObject. (When player leaves it's decreasing - but it's working fine) The problem is that when I'm testing it every time when 2nd and 3rd player joins it's adding 2 to the counter! 1st and every next is okay but 2nd and 3rd player adds 2! I'm getting sick of trying to fix this so maybe someone will know what's wrong. (p.s. and yeah, I need that to be detected by trigger... not for example simply adding 1 to counter when someone joins...) Here is part of the script: public GameObject gameDirector; public float maxPlayersOnArena = 20; public float countOfWaitingPlayers = 0; \\\ void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { if (countOfWaitingPlayers < maxPlayersOnArena) { countOfWaitingPlayers ++; } else { gameDirector.gameObject.SetActive (true);}}}
Your answer
Follow this Question
Related Questions
collider doesnt work the 2nd time 1 Answer
Pinwheel prevents player by moving 0 Answers
Problem tags to animation 0 Answers