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