Hey guys. I really need your help.
I try to rotate a GUI button 90° , when it was pressed. This is the relevant Code.

var rotate=false;
var rotAngle : float = 0;
var rotAngleCache : float = 0;
var pivotPoint : Vector2;

function update()
{
while(rotAngle<rotAngleCache&&rotate==true){rotAngle+= 0.001*Time.deltaTime;}
}

function OnGUI() {
		pivotPoint = Vector2(Screen.width-220+100,Screen.height-200+100);
		GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
	if(GUI.Button(Rect(Screen.width-220,Screen.height-200,300,300),Button,ButtonStyle))
	{
		rotAngleCache=0;
 		rotAngleCache=rotAngle+90;
 		if(rotAngleCache>360){rotAngleCache=rotAngleCache-360;}
 		if(rotAngle==360){rotAngle=0;}
		//while(rotAngle<rotAngleCache){rotAngle+= 0.001*Time.deltaTime;}
		rotate=true;	
	}   
}

The button actually rotates but not slowly. It is immediately 90° further.
Anyone knows why?

  1. This while loop will keep going until it is 90, then Update is over.
  2. Your Update function should be capitalized (?)

Try this code:

function Update()
{
	if(rotAngle<90){
		rotAngle+=0.001*Time.deltaTime;
	}else if(rotAngle>90){
		rotAngle=90;
	}
}

Also, remove anything that updates your rotation angle inside your OnGUI code, as that gets called twice per update.