How do you give each player a separate camera?

How do you give each player a separate camera?
I am making a 3d multiplayer game, and I want each player to have a separate camera. Whenever a player joins, I create a new camera. The problem is, while there are two cameras in the scene, one for each player, both players are looking out of the same location, and only one player can control the location for both players.

I know that whatever camera is tagged “MainCamera” is the one that the player uses. Because of that, I am trying to set each player’s camera to the main camera every update, so that they will use the correct one, but that isn’t working. This is the code for that:

GameObject[] cameras = GameObject.FindObjectsOfType<GameObject>();
        foreach (GameObject c in cameras) {
            if (c.tag.Contains ("Camera")) {
                if (c.GetComponent<PlayerScript> ().team != team) {
                    c.tag = "Camera";
                } else {
                    c.tag = "MainCamera";

I also tried doing this:

GameObject[] players = GameObject.FindGameObjectsWithTag("MainCamera");
       foreach(GameObject i in players) {
            i.GetComponent<Camera>().enabled = false;
        gameObject.GetComponent<Camera>().enabled = true;

(The script for this is attached to the camera, and the script has a team variable to tell which player it is supposed to be.)

Neither of those worked, and I am not sure how else to make it so that the players use the correct camera.

My players are spawned from the LobbyManager game object from the unity networking, and the player is a camera with a movement script attached, and the above code, as well as other un-related stuff.

A new camera is created correctly when a player joins the game (I can see it from the inspector in the editor). The players should both be able to use the arrow keys to move their camera around, but only one of the players can move the camera, and both players’ are seeing from the same spot (the second player’s view will move around with the first), so it seems that they are both looking out of the same camera, and the second one is unused.

I would like both players to have their own cameras, and be able to move their cameras around.

I am using the built-in unity networking libraries, and unity 5.4.1

Hey, I’ve just got a suggestion. There’s are a few youtube tutorials I’d highly reccomend concerning this issue…

Try looking at these tutorials, I’d highly recommend learning something from this guy:

Or this:

I personally like the idea of using Photon (also Quill18 is excellent!), but if that’s not your thing then best of luck :wink:

Here’s a snippet of my code so you can see what I do for cameras - might provide some help, probably not though:

//Disable the overheadCamera (by the way, this is just my Main Scene// //Cam)
                overheadCam = GameObject.FindGameObjectWithTag("Cam");
                //Instantiate the new camera and player (shouldn't matter if you //use photon or not.
//just be sure to enable to camera and the character controller and have //them disabled by default).
                player = PhotonNetwork.Instantiate(, spawnPoint.transform.position, Quaternion.identity, 0);
                playerCam = PhotonNetwork.Instantiate("PlayerCam", spawnPoint.transform.position, Quaternion.identity, 0);
                playerCam.GetComponent<Camera>().enabled = true;
                playerCam.GetComponent<CameraControllercs>().enabled = true;
                playerCam.GetComponent<CameraControllercs>().target = player;