- Home /
Find gameobject by Networkplayer?
On the server side of my game I have a player.cs script attached to every playerprefab on the scene. What I need is to get the player script on the gameobject owned by a specific networkplayer.
The reason I'm using networkplayer is because this happens OnPlayerDisconnected(NetworkPlayer)
So how am I supposed to do this? Oh and one more lil thing, are viewIDs unique per player or per gameobject? If one player owns two gameobjects, do they have same viewID?
Answer by Anxo · Oct 22, 2014 at 09:09 PM
Actually, disregard my last answer, what is much eaiser is to just associate the Networkplayer with a player gameobject when they connect to the server,
OnPlayerConnected(Networkplayer playerNP){
// here you instantiate your player right? Add them to a List and add the networkplayer to a list as well, that way the int ids both
}
Then you just get the int on disconnect with
int disconnectedPlayerID = NetworkPlayerList.IndexOf(NetworkPlayerDisconnecting);
Destroy(PlayersList[disconnectedPlayerID]);
WUCC
Yeah after I posted this I kept on searching and apparently there's no other way or no unity method for doing this so I started doing what you suggested already hah. Thanks thought, I didn't want to have to deal with arrays tho :(
Answer by 03gramat · Jan 15, 2015 at 02:18 PM
viewId's are unique to the object but should match across all clients. That viewID is owned by the NetworkPlayer that created it (or re-set it's ID) but it's best to have all viewID's owned by the server and have the clients just know what objects they are allowed to control, Here's a tutorial that might help: