How to access to a variable from another script that keeps changing

So I have a script with an int (currentCamera) that keeps changing

public class Player : MonoBehaviour
{
    public int currentCamera = 1;

    private void Update()
    {
        ChangeCameras();
    }

    void ChangeCameras()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            currentCamera++;

            if (currentCamera > 2)
            {
                currentCamera = 1;
            }
        }
    }
}

And on the other script from which I want to access that variable I do this

public class MouseLook : MonoBehaviour
{
    Player playerScript;
    [SerializeField] GameObject player;
    
    private void Awake()
    {
        playerScript = player.GetComponent<Player>();
    }

    private void Update()
    {
        Debug.Log(playerScript.currentCamera);
    }
}

So the thing is that when currentCamera == 1, the Console will show the value correctly, but when it changes to 2, it won’t show it. In fact, it will stop showing anything until it changes to 1 again.
I really don’t know what to do

Hello,

This code should work…

If all references are correctly assigned (no null reference errors)

Debug.Log(playerScript.currentCamera); should be showing your int currentCamera vale. Try use to be sure, but it should be the same…

Debug.Log(playerScript.currentCamera.ToString());

Maybe not first frame, because you dont know which update is executed before, but the second frame after changing currentcamera value, it should.

Are you sure there arent other errors?

I tried it, it doesn’t work. But the mainly reason why I was debugging this value, is because I have this function

void ManageCursorForCameras(int camera)
    {
        if (camera == 1)
        {
            Cursor.lockState = CursorLockMode.Locked;
        }
        else
        {
            Cursor.lockState = CursorLockMode.None;
        }
    }

Which is on the MouseLook script, and recieves the currentCamera int from the Player script as an argument. And it doesn’t seem to “recognize” the currentCamera int when its equal to 2, so it doesn’t work? I really don’t know why this happen.
I even tried changing the currentCamera value manually equal to 2, and STILL doesn’t work, only if currentCamera == 1.
It really is so strange