new to Unity: rotation on z-axis?

Hi all, I’m new to Unity (come from an as3 background), was wondering if someone can help me with regards to rotation, which seems incredibly complicated for some reason.
Basically I want the user to click on an object, and that object will rotate 90 degrees along the z axis (moving a certain amount of degrees per frame, rather than popping straight to the rotation). Once that rotation has complete they can then click it again and it rotates another 90 degrees. Here is the code I have created. It rotates the first time, but my check for:
if(Mathf.Floor(transform.eulerAngles.z)!=rotAngle){
…doesn’t work as the transform.eulerAngles.z number only gets to 134 then goes back to 0. Can anyone give me some help as to how to solve this?

var zRot:int = 0;

var rotating:boolean = false;

var speedOfRotation:int = 1;

var lastRotation:int = 0;

var rotAngle = 90;

var targetPosition;

function Update () {

rotatePipe();

}

function OnMouseDown(){

//if it is not currrently moving . . .
if(!rotating){

rotating = true;

rotAngle+=90;

targetPosition = Quaternion.Euler (90 , 0, rotAngle);

}

}

function rotatePipe(){

if(Mathf.Floor(transform.eulerAngles.z)!=rotAngle){

Debug.Log(Mathf.Floor(transform.eulerAngles.z)+“:”+rotAngle);

//continue
makeRotate();

}else{

rotating = false;

}

}

function makeRotate(){

//rotate object through a set time
transform.rotation = Quaternion.Slerp(transform.rotation, targetPosition,Time.deltaTime * speedOfRotation);

}

Try this:

http://forum.unity3d.com/viewtopic.php?t=12579&start=1

also:

http://forum.unity3d.com/viewtopic.php?t=11781

Don’t use Update, use coroutines.

–Eric

Brilliant, thanks! Just incase anybody is wondering, my script now looks like:

var rotating:boolean = false;

var speed:int = 4;

function Update () {
}

function OnMouseDown(){

//if it is not currrently moving . . .
if(!rotating){

rotatePipe();

}

}

function rotatePipe(){

rotating = true;

var oldRotation = transform.rotation;

transform.Rotate(90, 0,0);

var newRotation = transform.rotation;

for (t = 0.0; t <= 1.0; t += Time.deltaTime*speed) {

transform.rotation = Quaternion.Slerp(oldRotation, newRotation, t);

yield;
}

rotating = false;

transform.rotation = newRotation; // To make it come out at exactly 90 degrees

}