Forcing a rotation point

I have a script that checks the rotation of an object and if it hits a certain range, it will force it to rotate to a point. The problem is that it won't work properly, like it stops a 85.299 instead of 90.0 despite the scripting.

I need a reason for this.

function Update(){
if(spinTimer <= 0){
    Stop();
    }
}

function Stop(){
spin = false;
stop = true;

if(transform.rotation.x <= 0.0|| transform.rotation.x >= 151.0 && transform.rotation.x <= 180.0||transform.rotation.x >= 331.0 && transform.rotation.x <= 360.0){
transform.rotation.x = 0;
}
else if(transform.rotation.x >= 1.0 && transform.rotation.x <= 30.0|| transform.rotation.x >= 181.0 && transform.rotation.x <= 210.0){
transform.rotation.x = 30.00;
}
else if(transform.rotation.x >= 31.0 && transform.rotation.x <= 60.0 ||transform.rotation.x >= 211.0 && transform.rotation.x <= 240.0){
transform.rotation.x = 60.00;
}
else if(transform.rotation.x >= 61.0 && transform.rotation.x <= 90.0|| transform.rotation.x >= 241.0 && transform.rotation.x <= 270.0){
transform.rotation.x = 90.00;
}
else if(transform.rotation.x >= 91.0 && transform.rotation.x <= 120.0||transform.rotation.x >= 271.0 && transform.rotation.x <= 300.0){
transform.rotation.x = 120.00;
}
else if(transform.rotation.x >= 121.0 && transform.rotation.x <= 150.0|| transform.rotation.x >= 301.0 && transform.rotation.x <= 330.0){
transform.rotation.x = 150.00;
}
//Reset the Timer
spinTimer = 5;
}

2 Answers

2

Transform.rotation is a quaternion, not a set of Euler angles.

You probably want to use:

transform.eulerAngles

Which is a Vector3 and can be accessed to as

transform.eulerAngles.x
transform.eulerAngles.y
transform.eulerAngles.z

Writing allowed... :)