I am trying to make a game like ‘What the box’ which is a multiplayer game. To make use of third person camera, I added a camera as child of player which continuously follows it. This worked fine for a single host but as soon as a client connected the camera focused on the client; even if the host was controlled, its actions were captured by the clients cam. What is the problem here or does anyone have any better solution?
Sorry, not downloading your source files. Generally you should not make cameras part of your player prefab, since you’ll end up with as many cameras in the scene on every client as there are players. Create one camera, and if you want it a child of the player then set it as a child of the player after the player is spawned on that client. Check for isLocalPlayer to see if that is the right player to child your camera to.
On your player you could include code something like this on a NetworkBehavior:
void Start()
{
if (isLocalPlayer)
{
GameObject cameraObject = GameObject.FindGameObjectWithTag("MainCamera");
if (cameraObject != null)
{
cameraObject.transform.parent = gameObject.transform;
}
else
{
Debug.Log("Couldn't find MainCamera in scene");
}
}
}