- Home /
Question by
TheRealDia · Dec 25, 2017 at 09:26 PM ·
cameramovementunassignedreferenceexcept
Odd problem: UnassignedReferenceException: The variable cams of button1Press has not been assigned.
Hello. I was trying to make a camera move using the arrow keys, when this error appeared: UnassignedReferenceException: The variable cams of button1Press has not been assigned. You probably need to assign the cams variable of the button1Press script in the inspector. I have already assigned the variable in the Inspector, so I am not sure why this is happening. This is the script:
public void Update () {
if (Input.GetKey(KeyCode.LeftArrow)) {
Left ();
}
if (Input.GetKey(KeyCode.RightArrow)) {
Right ();
}
}
public void Left() {
if (position == 1) {
cams.transform.position = new Vector3 (0, 0, 0);
position = 0;
}
}
Comment
Can you post a picture of the inspector with this object selected? Also, can you show your declaration line where you declare the cams variable?
Sure.
public Text Number;
public int position;
public Display view;
public Camera cams;
screen-shot-2017-12-25-at-42008-pm.png
(25.5 kB)
Also, in case you are wondering, the whole script is over 2000 lines on, so I can't really copy and paste the entire thing.
Your answer
![](https://koobas.hobune.stream/wayback/20220612145219im_/https://answers.unity.com/themes/thub/images/avi.jpg)