Hi,
My situation goes like this: When a player joins a game, there is a clone of its avatar created on each instance of the game. When the player leaves the game (even with Alt+F4) there is a Network.DestroyPlayerObjects(Network.player); running on the server that destroys all of its objects, including the clones created on other machines or game instances.
However, when the player that leaves the game (Alt + F4) is the one that created it, that instruction is not executed since, the server that should run the OnPlayerDisconnected function doesnt exists anymore and the OnDisconnectedFromServer runs but doesnt allow me to execute the Network.DestroyPlayerObjects(Network.player);
Therefore, I put a Destroy(gameObject) inside the cloned object. Here it’s the piece of code:
function OnDisconnectedFromServer(info : NetworkDisconnection)
{
if(propietario.ToString() == '0' !alreadyDestroyed)
{
Debug.Log('Im getting rid of the clone');
alreadyDestroyed = true;
Destroy(gameObject);
}
}
The propietario variable has been feeded on the Start function with the networkView.owner, no matter to who it belongs. Since all other clones are erased from universe when player has disconnected, I only ask if the clone to which the script is attached to is the GameCreator (isServer).
The boolean variable at the condition aims to avoid the double display of the Debug.Log message and any error that the re excecution of the bucle would bring alone. However the debug message always appears twice! My logic tells me it shouldnt because I’m testing the game with only two players and only one of them has 0 as Network.Player. The code is active only for clones
if (!networkView.isMine) //Then, I am a clone.
{ //Do many things
}else{
enabled = false;
}
With the Destroy(gameObject), the game freezes. If I comment it, the game continues but the clone of the GameCreator player remains.
Please help!