简体   繁体   中英

Unity networking separate clients

I can't wrap my head around how to separate or distinct connected clients. I have done one of the many networking tutorials out there that get you to move blocks in another window through the unity MasterServer . I currently have my own implementation which is a Lobby that lists the servers created, players can connect to these servers and once full a new scene loads for all the players connected.

Now I need them to act in turn (turn based) spawning objects in there "own" color. Something like a check for a player ID, but then I need a complete list of all connected ID's as well to check against.

What you probably want is

MasterServer.RequestHostList
MasterServer.PollHostList
HostData.connectedPlayers

The MasterServer.RequestHostList requests for a host list on the MasterServer. You can then access this list through MasterServer.PollHostList.

MasterServer.PollHostList returns an array of HostData. You can use this array to query for the players connected to each Host.

Links below to the respective docs on Unity API reference. Each link has a great example on usage.

MasterServer.RequestHostList
MasterServer.PollHostList

HostData.connectedPlayers

Your server should have, for each of your connected clients, one copy of the GameObject that is Network.Instantiated by the clients and that the clients use to send information to the server.

The owner of the NetworkView in each of these objects is the client that instantiated them, and you can find it in "newtorkView.owner".

But you already have the separate GameObjects and that might be enough for your needs; each of them has a different instance of the script your clients use so they can be made to pick a spot in the turn queue and a different color each.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM