- Home /
Rotate a sphere one time
Is there a script i can atatch to a GUI button that make a sphere rotate once and then stop?
Answer by Peter G · Feb 17, 2011 at 09:51 PM
You could do something like this:
var mySphere : Transform;
private var canRotate = true;
var rotateSpeed : float = 90.0; var rotateDegrees : float = 360;
function OnGUI () { if( GUI.Button() ) { //When the user hits the button: if(canRotate) { //check to see if we aren't already rotating Rotate(); }
else {
Debug.Log("Already Rotating");
}
}
}
function Rotate () { //simple while loop. check the syntax. I'm rusty on my js. while(var i : float < rotateDegrees) { mySphere.transform.Rotate(0, rotateSpeed Time.deltaTime, 0); //rotate your sphere by rotateSpeed times by deltaTime i += rotateSpeed Time.deltaTime; yield; //wait a frame } canRotate = true; //we can rotate again. }
Your answer