Hi,
I’m writing a little script where I need to know on the server when a remote client has spawned his/her localPlayer. So I’m using the OnServerAddPlayer method of the NetworkManager class and it’s working correctly. My problem comes when I want to be noticed on the server when the remote client destroys his/her localPlayer prefab. When I’m using OnServerRemovePlayer it is not called by the engine (I tried to log a message). And I precisely need to know when the player prefab has been removed so I can’t use OnServerDisconnect because I need to call an RPC on all my clients otherwise I’ll receive a message like: “Cannot call RPC on … the game object has not been spawned”.
public override void OnServerRemovePlayer (NetworkConnection conn)
{
base.OnServerDisconnect (conn);
Debug.Log("NOT CALLED HERE");
if (numPlayers < playerMinToStart) {
foreach (GameObject p in GameObject.FindGameObjectsWithTag("Player")) {
PlayerStatus status = p.GetComponent<PlayerStatus> ();
if (status) {
//status.RpcSleep ();
}
}
}
}
Any ideas ?
Thank you in advance.