- Home /
Why is this variable changing for no reason?
I have a script called Scroll, which has a variable r that is supposed to change only based on player input. Or, if it goes beyond the range it is supposed to be in, it corrects, but it keeps jumping from 0 where it starts, to 5.759587, which is approximately 11*PI/6.
The code for the script is:
var r : float;
function Update () {
while (r<0){
r+=Mathf.PI*2;
}
while (r>Mathf.PI*2){
r-=Mathf.PI*2;
}
if(Input.GetButtonUp("Fire1")){
r-=Mathf.PI/6;
}
else if(Input.GetButtonUp("Fire2")){
r+=Mathf.PI/6;
}
}
There are other scripts that access r, but none of them modify it. After the initial jump from 0 to 11*PI/6, everything works the way it is supposed to. Why is this happening?
Comment
Best Answer
Answer by Rey · Dec 27, 2010 at 08:39 PM
It turns out left click was set to be the alternate button for fire1, so when I clicked on the game screen to activate it, it also triggered the script to change the variable.