Have each player of a multiplayer game have their own camera? (client-side camera)
Hello, I'm new to networking and I can't seem to figure out how to have each player of a simple multiplayer game have their own camera active which is a child of the player object. I've tried to disable the camera in the player from the start and enable it on client-side like this
public override void OnStartLocalPlayer(){
TheCamera.SetActive(true);
GetComponent<MeshRenderer> ().material.color = Color.blue;
}
but that did not work. In case anyone is wondering, my simple game is pretty much the same thing as what you would end up with if you followed this tutorial.
Answer by $$anonymous$$ · Jan 04, 2018 at 11:26 PM
Alright, I figured it out. I just put this code at the start of my player script.
void Start(){
if (isLocalPlayer) {
Camera.main.gameObject.transform.position = gameObject.transform.position + new Vector3 (0, 2, -4);
}
}
Also, I removed the camera from the player prefab so that there is only one camera in the game.
Your answer
Follow this Question
Related Questions
[UNet] How to make a client-side camera ? 5 Answers
LAN Auto find server/host 0 Answers
I have a problem with my Camera detecting and following the player!! pls help... 0 Answers
non-player object can't execute's "[Command]"'s attributes 0 Answers
[UNET] Spawn object on server BUT delete on your client 1 Answer