Hi,
I have an object that constantly rotates around its Y axis.
I want to change the direction of the rotation each time I press (either tap/hold) a button.
The direction of the rotation is fixed by an INT variable that is changed from 1 to 0 (1=right, 0=left).
I’ve written a function that is called inside FixedUpdate, and it basically works, but sometimes it “misses” and failed to change the variable.
private int RotationDirection;
void Start () {
RotationDirection=1;
}
void FixedUpdate () {
switchRotation();
}
void switchRotation(){
if(RotationDirection==0 && Input.GetButtonDown("Fire1")){
RotationDirection=1;
}
else{
if(RotationDirection==1 && Input.GetButtonDown("Fire1")){
RotationDirection=0;
}
}
}
Is there a way to change that variable in a “Full Proof” way?