I’ve been trying to wrap my head around Unity networking for a couple hours now, I’ve been using both Leepo’s zero to hero tutorial and the networking examples from Unity3d.com’s resources.
I have a basic connection working, where it network.instantiates a player prefab on a spawn point for both the server and the player that connects, and I’m limiting the control script on the player prefab based on NetworkView.isMine… which works fine.
But I’m trying to use Network.DestroyPlayerObjects in OnPlayerDisconnected, using a snippet from the docs… but it isn’t doing anything, so all the prefabs that were instantiated when the server connected and any clients connected still linger around.
Here is my code:
NetworkSpawn.js
var playerPrefab : Transform;
function OnServerInitialized(){
Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
}
function OnConnectedToServer(){
Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
}
function OnPlayerDisconnected (player : NetworkPlayer){
Debug.Log("Server destroying player");
Network.RemoveRPCs(player);
Network.DestroyPlayerObjects(player);
}
PlayerNetworkInit.js
function OnNetworkInstantiate (msg : NetworkMessageInfo) {
if (networkView.isMine){
Camera.main.SendMessage("SetTarget", transform);
}
else{
GetComponent("FPSInputController").enabled = false;
}
}