var playerPrefab:Transform;
function OnPlayerConnected()
{
var newTransform=Network.Instantiate(playerPrefab,transform.position,Quaternion.identity,0);
}
function OnPlayerDisconnected(player:NetworkPlayer)
{
print(player.ipAddress);
Network.DestroyPlayerObjects(player);
}
function OnDisconnectedFromServer(info:NetworkDisconnection)
{
Application.LoadLevel(Application.loadedLevel);
}
What makes me confused is that when a player disconnected from server the function OnDisconnectedFromServer would execute and destory playerobjects of the disconnected player ,but the playerobjects of the disconnected player are still there when i test ,they are not destroyed.Why?
var playerPrefab:Transform;
function OnPlayerConnected()
{
var newTransform=Network.Instantiate(playerPrefab,transform.position,Quaternion.identity,0);
}
OnPlayerConnected() is only called by the server and if the server instantiates the playerPrefab, the server is the owner not the player, means the Player has no objects associated to him so
function OnPlayerDisconnected(player:NetworkPlayer)
{
print(player.ipAddress);
Network.DestroyPlayerObjects(player);
}
wont delete anything. You could either let the client instantiate the prefab, then the above would work or destroy it by the viewId/gameObject like superme.