- Home /
Does Network.connections.Length include itself?
I am using Network.connections.Length to display the number of players in an online game, but when I start a server (As the server) I am told there are no players in the game, even though I am in it. Is this because Network.connections.Length does not include itself, or is it more likely a problem in my coding?
Answer by Bunny83 · Oct 30, 2012 at 12:16 AM
Network.connections, as the name said, only holds network connections. When the server is alone, he's not connected to anyone, so the Length is of course "0". When one player joins there is one connection from this new player to the server. If three clients joined the server there are three connections.
Keep in mind that Network.connections on clients will always be either "0" or "1", nothing else. A client can only be connected to one server at a time. Network.connections can be used to count the player on the server, but there's no way to get this information on a client. A client has no idea how many other players are connected to the server. You have to count the players on the server and send this information explicitly (via RPCs) to your clients.
hey @Bunny83 I want to get server networkplayer from the client. So shouldn't I just use Network.connections[0]
to get the server player from the client?? Somehow it's not working for me. :(
@BlackPanda: Yes, if the client is connected to a server then Network.connections[0] represents the server player on the client machine. $$anonymous$$eep in $$anonymous$$d that not all fields of the NetworkPlayer has to be set. You can use that reference to send RPCs to that player (RPC$$anonymous$$ode.Server would do the same), or check a NetworkView if it's owned by the server player.
If you want to make other information available to other players (like the GUID) you have to use RPCs to propagate that information to the others.
If you have more questions you might want to ask an actual question ins$$anonymous$$d of posting a comment here ^^.