- Home /
Managing turns in online turn-based multiplayer game using Unity Networking
I am developing a turn-based online multiplayer game. I got to a point where I need to manage which player takes its turn. The way I though to do this would be to have clients manage finishing your own turn and server managing starting turn for players. Im my mind this could be achieved by having a state machine running on the server that loops through all the players and notifies them when they are to make a move.
So the desired game flow would look like this:
Player makes a move
Player clicks a button "End turn" and is not allowed to take any more action( e.g. by setting a
false
flag somewhere)This runs a server command saying "Hey, a turn just ended" (with no need to specify which player ended his turn)
The next player from the list id notified it's his turn. Now this is the part I need help with. I can see this handled different ways:
a. Server sends a message with active player id to all clients. Clients then check to see if the id is theirs, and one of them takes turn. This allows all clients to do stuff like highlighting active player, but requires an active client to recognize itself from the id.
b. Server sends a message to one specific client. Other clients don't know who takes turn, only if it's if them someone else. This requires sending a message to a specific client.
c. The state machine is running on clients, not on the server. Server only takes in a
endTurn()
command from one of the players and broadcasts it to the other ones. Clients then handle turn management themselves. Server doesn't know which player takes turn.
It seems to me that a is the best, but how can I distinguish clients? Is there some sort of network-wide ID system I can use or do I have to write it myself?
If there's a better way to implement this, please tell me how.
Also, is there a way for the server to call a method on one specific client? (not all at once) If so, how do I do it?