I have been working in unity for a little while now, and have gotten a basic multiplayer setup to work, from following this tutorial. However, I want to add a couple more things, one of them being a camera to follow each player. I have looked this up already and even found a comment from the creator of that tutorial. So I followed what he explained, and have this code:
function spawnPlayer(){
var player:GameObject=Network.Instantiate(playerPrefab,spawnObject.position,Quaternion.identity,0);
Destroy(Camera.main);
if(player.networkView.isMine){
var playercam:Transform=player.transform.find("Camera");
playercam.tag="MainCamera";
}
}
I forgot to mention, there is a camera parented to the player object, which is selected as the 'playerPrefab' game object.
This kind of works, but not really. When I start a server, the camera follows you fine. However when I open another file and join that host, it starts getting all weird on me. By weird, I mean that when i move on the server game, the camera follows the server player on the client game, and when moving on the client game, the camera follows the client on the server game. To me this makes no sense.
I'd appreciate anyone's input on this problem, or how it can be fixed. Thanks