Give each client his own camera
I have a player prefab and in it a camera. I can initalize the prefab no problem, and have each client control it's object, but I fail at enabeling for each client the right camera.
Thanks in advance
Answer by Icyteck01 · May 09, 2017 at 06:13 AM
Make another prefab for camera and atach it only if local player(not remote player)
Answer by SteenPetersen · May 09, 2017 at 12:05 PM
@Foberm I take it you are networking your game? are you using the built in system? In that case it may be a bit different.
I wrote my own server code and when someone logs in they get a prefab that has an ID attributed to it by the server along with a character controller.
inside the character controller I find the cameras script, and pass it my ID so it knows who to follow:
follow = GameObject.Find("CameraHolder").GetComponent<FollowPlayer>();
thisPlayerId = this.gameObject.name;
follow.SetTarget(thisPlayerId);
Then on the camera script I set its target to that ID:
public void SetTarget(string e)
{
lookAt = GameObject.Find(e).GetComponent<Transform>();
}
when loading in other players they get a similar prefab but without the character controller.
is this the sort of information you are looking for?
I believe if you are using the built in system you can just type in start()
if(!isLocalPlayer){
return;
}
//code to instantiate a camera
that way only the localplayer will get a camera.