# Rotate 90 over time on mouseDown

This is in the main character controller script and is controlled by a ray collision on an update function:

``````if (Input.GetMouseButtonDown(0)){
miniNode.GetComponent(rotationHandlerLeft).rotateLeftSmall();
}

``````

And this is what I have for moving the rotations right now which works great but Id love for there to be some smooth Animation over time that locks at 90 increments, these are in a seperate script that has no update function at the moment :

``````function rotateLeftSmall () {
transform.Rotate(Vector3.up*-90); // Rotate to the left
print("Left Rotation");
}

``````

I think this will work but im having trouble with where the updates go I think.

``````function rotateLeftSmall () {
transform.Rotate(Vector3.up * Time.deltaTime * -90)
}

``````

Use a coroutine:

``````private var rotating = false;

function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) {
if (rotating) return;
rotating = true;

var startRotation = thisTransform.rotation;
var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
var t = 0.0;
var rate = 1.0/seconds;
while (t < 1.0) {
t += Time.deltaTime * rate;
thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
yield;
}

rotating = false;
}

``````

Which is called like this:

``````RotateObject(transform, Vector3.up*-90, .5);

``````

Well, what you want to do is something along these lines:

``````function Update () {
if (Input.GetMouseButtonDown(0)){
transform.Rotate(Vector3.up * Time.deltaTime * -90);
}
}

``````

This will rotate your object to the left when you press mouse 0. Replace

``````if (Input.GetMouseButtonDown(0)){
miniNode.GetComponent(rotationHandlerLeft).rotateLeftSmall();
}

``````

with

``````if (Input.GetMouseButtonDown(0)){
transform.Rotate(Vector3.up * Time.deltaTime * -90);
}

``````

in your Update function.