I’ve recently downloaded and gone through the M2H networking tutorial. I’ve started modifying ‘example 4’ to create a 3rd person shooter demo. All is going well though I’d like to know the best way to have the server and clients disconnect from the game and reload the ‘menu’ scene.
At the moment I’m just calling ‘Network.Disconnect’ from the scoreboard script and all clients disconnect just fine.
I wanted to make sure if this is the way we would usually disconnect clients in Unity?
Is there a cleaner way I should be doing this, such as removing any buffered network packets first, removing game objects etc? Or do all objects / packets simply get deleted when I load a different scene?
not sure about this but a client disconnection would mean all his buffered packets will get dropped.
There is a command Network.Destroy in the manual. you could call that on the server and destroy all.
function OnLevelWasLoaded ()
{
if (Network.peerType == NetworkPeerType.Disconnected)
Destroy (gameObject);
}
That should do it.
Edit : this is for the case when you have reloaded a level, and disconnected before, so it cleans the game object. For other purpose, you must specify the right if condition.