Hi I recently started a old Unity Multiplayer Tutorial. I’m having some trouble with it. It’s also writen in java script, which I don’t really know as I work in C#. help would be greatly appreciated. the code underneath should destroy and disconnect a player compleatly, but it doesnt seem to work. does it need to be called when the disconect button is pressed? or is something just wrong there? if it needs to be called how would that look? just OnPlayerDisconnected(What would go here?);
function OnPlayerDisconnected (player : NetworkPlayer) {
Network.RemoveRPCs(player, 0);
Network.DestroyPlayerObjects(player);
}
also how would this be writen in c#?:
for (var go : GameObject in FindObjectsOfType(GameObject))
Thanks in advance 
Please use code tags.
void OnPlayerDisconnected (NetworkPlayer player) {
Network.Destroy(player);
Network.RemoveRPCs(player);
}
http://docs.unity3d.com/Documentation/ScriptReference/Network.OnPlayerDisconnected.html
You can change the language in the scripting reference to C#
hi apples
I can change java script to C# just fine its just this im not sure of:
for (var go : GameObject in FindObjectsOfType(GameObject))
the disconnect code just isnt being called when someone disconnects. thats the part I’m trying to understand.
maybe its cause im testing the server’s disconnection and not a client. but shouldent the server also destroy its stuff when its disconnected?
Try this
foreach(GameObject go in FindObjectsOfType(typeof(GameObject)))
{
// do something here
}
maybe you need to change the FindObject part and use a variable instead:
GameObject[] foundObj = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach(GameObject go in foundObj)
{
// do something here
}
OnPlayerDisconnected is not called on the server when the server disconnects, OnDisconnectedFromServer is.