Differentiating between players

Hi, I’m trying to get different cameras to follow the two players, however because the two players use the same prefab both cameras just follow the first one to spawn in. This is my script for the cameras right now.

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class CameraController : MonoBehaviour {
    public float speed;

    public GameObject Pl;
    private Vector3 offset;
    private float timer;


    void Start ()
    {

        Pl = GameObject.Find("GameObject");

        offset = transform.position - Pl.transform.position;
        speed = 4;


    }

    void LateUpdate ()

    {
     
        if (GameObject.FindWithTag("Player")) {
            Pl = GameObject.Find ("Player(Clone)");

        } else {
            Pl = GameObject.Find ("GameObject");
        }



        transform.position = Pl.transform.position + offset;
     
    }
}

Any help would be appreciated.

Check for isLocalPlayer on the Player object. That is the one that represents the player on this client.

So on a NetworkBehaviour script on the Player object I’d just add a method like this:

public bool LocalPlayer()
{
    return isLocalPlayer;
}

You also don’t want to run GameObject.FindWithTag on every LateUpdate, and you should really avoid using GameObject.Find at all, ever. I’d change your script to something like this, where that LocalPlayer method above has been added to a script called Player.cs attached to the player gameobject (which I’m calling on line 31).

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class CameraController : MonoBehaviour {
    public float speed;

    public GameObject Pl;
    private Vector3 offset;
    private float timer;


    void Start ()
    {

        //Finding any GameObject named "GameObject" is highly prone to breaking
        //Just set your desired offset here, or actually create a specific GameObject you use for calculating offset and assign it a unique tag instead of just using the generic "GameObject" name
        offset = new Vector3(100,100,100);
        speed = 4;

    }

    void LateUpdate ()
    {
 
        if (P1 == null)
        {
            GameObject[] playerObjects = GameObject.FindGameObjectsWithTag("Player");
            foreach (GameObject player in playerObjects)
            {
                if (player.GetComponent<Player>().LocalPlayer())
                {
                    P1 = player;
                }
            }
        }

        //Now if we have set the P1 object above we can update position to it here
        if (P1 != null)
        {
            transform.position = Pl.transform.position + offset;
        }
 
    }


}

If you do it like above, your camera should be following the local player on each client.

That worked, thank you so much