- Home /
How to detect when player disconnects from master server?
Hello,
I am currently almost done with a Capstone project I have been working on for College. I had not had the need to ask any questions thats to this community and various tutorials; that is until now.
My game is a driving game that simulates how the roads/driving are/is in Puerto Rico. One part of this project is to create multiplayer, which we decided to use the Master Server provided by Unity.
I have the networkViews running and I can get players to join and interact the problem is I would like to detect for the Network.isServer side when a player has disconnected, so that i can reduce the number of players and Destroy that gameObject.
So my question is this, how do I detect from the server side, that a player has disconnected and destroy the object? I have 1 week left to finish and this would be a nice feature to have.
Thanks in advance, I really need your help if you can help me. I would not ask if I did not :(
P.S. The Server side is another player A.K.A. the Host
Answer by gajdot · Nov 15, 2013 at 12:34 PM
There is a function called OnPlayerDisconnected which is called every time when a player disconnects from the server, maybe you are looking for that one. I used a code like this:
void OnPlayerDisconnected(NetworkPlayer networkPlayer)
{
// When the player disconnects remove them across the network, so nobody can see them
Network.RemoveRPCs(networkPlayer);
Network.DestroyPlayerObjects(networkPlayer);
}
Thanks alot! this is what I was looking for; however I can not believe how simple it is O_O. you are a life saver :D
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Network disconnect player 1 Answer
Unhandled message error when registering host 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers