How to make my camera follow a prefab and update it to follow the instance of same prefab the genera

here’s my camera move code

    [SerializeField] Transform playerTransform;
    private PlayerMove playerMove;
    // Start is called before the first frame update
    void Start()
    {
        playerMove = FindObjectOfType<PlayerMove>();
    }

    // Update is called once per frame
    void LateUpdate()
    {
        Vector3 temp = transform.position;

        temp.x = playerTransform.position.x;

        transform.position = temp;
    }
}

here’s my prefab player

public  void NewObject()
    {
      
      
            Instantiate(Player, lastCheckpointPos, Quaternion.identity);
       
       
    }

here’s my list

public List <GameObject> numberOfPlayers;
    [SerializeField] GameObject grave;

    // Use this for initialization
    void Start () {
        playerRigid = GetComponent<Rigidbody2D>();
        box = GetComponent<BoxCollider2D>();
        manageGame = FindObjectOfType<ManageGame>();
        numberOfPlayers.AddRange(GameObject.FindGameObjectsWithTag("Player"));
    }

    // Update is called once per frame
    void Update()
    {

        player = GameObject.FindGameObjectsWithTag("Player").Length;

Hi,
Why not let the script that instantiate new players, also update the camera to follow the player of choice?

1 Like