Camera won't follow player

I’m following a tutorial (beginner) on first person camera movement and playercontroller scripts, this script is supposed to lock my player camera to an empty object in my player called CameraPos, but it doesn’t work. Unity isn’t coming up with any errors. What’s wrong? Any ideas would be appreciated.

here is the player camera script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCam:MonoBehaviour
{
public float sensX;
public float sensY;

public Transform orientation;

float xRotation;
float yRotation;

private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}

private void Update()
{
// get mouse input
float mouseX = Input.GetAxisRaw(“Mouse X”) * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw(“Mouse Y”) * Time.deltaTime * sensY;

yRotation += mouseX;

xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);

// rotate cam and orientation
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}

And here is the Move Camera script (which isn’t working):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCamera : MonoBehaviour
{
public Transform cameraPosition;

private void Update()
{
transform.position = cameraPosition.position;
}
}

Camera stuff is pretty tricky… I hear all the Kool Kids are using Cinemachine from the Unity Package Manager.

There’s even a dedicated forum: Unity Engine - Unity Discussions

If you insist on making your own camera controller, do not fiddle with camera rotation.

The simplest way to do it is to think in terms of two Vector3 points in space: where the camera is LOCATED and where the camera is LOOKING.

private Vector3 WhereMyCameraIsLocated;
private Vector3 WhatMyCameraIsLookingAt;

void LateUpdate()
{
  cam.transform.position = WhereMyCameraIsLocated;
  cam.transform.LookAt( WhatMyCameraIsLookingAt);
}

Then you just need to update the above two points based on your GameObjects, no need to fiddle with rotations. As long as you move those positions smoothly, the camera will be nice and smooth as well, both positionally and rotationally.

If you think what you have now should be working, well that only means…Time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

You should actually be able to just set the Main Camera of the scene as a child of the Player node like this, and it’ll follow the player automatically without any additional coding needed.