How to make the camera follow after the selected character?

i have a selection character script `using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.SceneManagement;
public class skinselect : MonoBehaviour
{
private GameObject skinlist;
public int index;

// Start is called before the first frame update
private void Start()
{
    index = PlayerPrefs.GetInt("CharacterSelected");
    skinlist = new GameObject[transform.childCount];
    for(int i =0; i < transform.childCount; i++)
    
        skinlist *= transform.GetChild(i).gameObject;*

foreach(GameObject go in skinlist)
{

go.SetActive(false);
if (skinlist[index])
skinlist[index].SetActive(true);
}

}
public void ToggleLeft()
{
skinlist[index].SetActive(false);
index–;
if (index < 0)
index = skinlist.Length - 1;
skinlist[index].SetActive(true);
}
public void Toggleright()
{
skinlist[index].SetActive(false);
index++;
if (index ==skinlist.Length)
index = 0;
skinlist[index].SetActive(true);
}
public void confirmbutton()
{
PlayerPrefs.SetInt(“CharacterSelected”, index);
}
}
and camera follow script
using UnityEngine;

public class camerafollow : MonoBehaviour {

public Transform player;
public float smoothSpeed = 0.125f;
public Vector3 offset;
void LateUpdate()
{
transform.position = player .position + offset;
}

}

but i dont know how to make the camera follow after the selected character

I would recommend using this script. It works perfectly for me so it might be what you’re looking for. Just make sure to add the intended player to be targeted into the public variable. This script will find the current location of the camera in relation to the targeted object and then maintain that location in relation to the target as the player moves around. If your player does not rotate, then you can just add the camera as a child of the player instead of needing this script.

public class CameraController : MonoBehaviour
{
    public GameObject Target;

    private Vector3 offset;

    // Start is called before the first frame update
    void Start()
    {
        offset = transform.position - Target.transform.position;
    }

    // Update is called once per frame
    void LateUpdate()
    {
        transform.position = Target.transform.position + offset;
    }
}

If you want this script to automatically find the player, you can add this script into the Start() block.

Target = gameObject.Find("PlayerName");

Replacing PlayerName with the name of the target for the camera and making the Target variable private.
I hope this helps!