How can I work out how many players are alive?
I have a 2D networked game. When all the players are dead I need them to respawn and start the game again. My question is how can I get a value with how many players are currently alive. My script uses Prefabs and spawns them in for all the players. All help is appreciated.
Answer by fishbrainz · Apr 12, 2016 at 09:38 AM
Try this: First off if you dont have a server managing the communication between your game clients, you should define one of your players's clients as a Master Client, the one that makes the decisions for all the other clients that you want to control, such as respawn.
Either on the server or master client keep a reference of each player connected to your networked play session, and ad a bool to that reference "_isDead", or something like that, false at start. When a player dies update that bool to true, and parse each other player's reference to check their _isDead bool too for true aswell.
If all the player's references have their _isDead bool true send a request from your server/master client to the other clients to respawn and reset their _isDead bool back to false.
Your answer
Follow this Question
Related Questions
Trivia Game in multiplayer mode? 0 Answers
Network how to synchronize large tilemap that's made up of bits 0 Answers
Adventure Game Help 0 Answers
[SOLVED] PhotonNetwork.Instantiate cannot spawn players 0 Answers