Hi, the title says it all. I’m working on a online multiplayer game. When I start a server everything is fine, but when I connect as client a new prefab is made and controlable by the client. But the camera snaps to the wrong player. I tried it the camera.enabled=true; in the awake but that isn’t working.
Does anyone have any idea how to fix it?
Here’s my code:
#pragma strict
#pragma implicit
#pragma downcast
public var playerPrefab : Transform;
function OnServerInitialized(){
Spawnplayer();
}
function OnConnectedToServer(){
Spawnplayer();
}
function Spawnplayer(){
var myNewTrans : Transform = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
if(networkView.isMine){
camera.enabled = true;
}
}
function OnPlayerDisconnected(player: NetworkPlayer) {
Debug.Log("Clean up after player " + player);
Network.RemoveRPCs(player);
Network.DestroyPlayerObjects(player);
}
function OnDisconnectedFromServer(info : NetworkDisconnection) {
Debug.Log("Clean up a bit after server quit");
Network.RemoveRPCs(Network.player);
Network.DestroyPlayerObjects(Network.player);
/*
* Note that we only remove our own objects, but we cannot remove the other players
* objects since we don't know what they are; we didn't keep track of them.
* In a game you would usually reload the level or load the main menu level anyway ;).
*
* In fact, we could use "Application.LoadLevel(Application.loadedLevel);" here instead to reset the scene.
*/
Application.LoadLevel(Application.loadedLevel);
}