The player of the main camera is to follow every solution path.

for camera tracking code;
Using System. Collections;
Using System. Collections. Generic;
Using UnityEngine;
Using UnityEngine. UI;
Public class CameraController: MonoBehaviour
{
Public GameObject Player;
Private Vector3 offset;
Void Start()
{
Offset = transform. Position - Player. Transform. Position;
}
// Update is called once per frame
Void LateUpdate()
{
Transform. Position = Player. Transform. Position + offset;
}
}
I used your code, but how can I make the camera rotate left or right when the Player turns left or right? Can you help me?

Just make the camera a child of the player object and it will inherit every transform value.

In case you don’t want to (although it would be more performant) you can do the same you did for the position but using transform.rotation.