- Home /
Network Player ID
I am making a RTS type game for online use so you can battle your friends/enemies, but I have ran into a problem. I am using arrays to store each players information, each has an index which equals the players ID. In game I run into problems because the players ID is set to one no matter when they joined the game, thus they all share the same name, color, faction, etc. is there a way to get a player ID as an integer(Int)? earlier I used Network.connections.Length, but that didn't work because each player only has 1 connection, which is to the server.
Answer by DellanX · Apr 21, 2012 at 09:49 PM
I figured it out after posting the question. here is my code:
void OnPlayerConnected(){
Network.RPC("SetClientInfo",RPCMode.Others,Network.connections.Length);
}
[RPC]
void SetClientIngo(int PIN){
if(PlayerNumber == 0){//If the player number hasn't been sent. that way already set player numbers wont be reset.
if(PIN == 0)Debug.Log("Client Did not receive correct info");
else PlayerNumber == PIN;
}
}
Wouldnt that cause a problem when a player disconnects and a new player joins? if there are 3 players: playerA - id1 playerB - id2 playerC - id3
if playerB leaves and a new player joins, it would become: playerA - id1 playerC - id3 playerD - id3
?Unless i have it wrong :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613070607im_/https://answers.unity.com/themes/thub/images/avi.jpg)