- Home /
Rotate GUI Button slowly
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?
Try rotating it by adding a constant value * Time.deltaTime, ins$$anonymous$$d of adding 90 with one go.
Answer by LemonLake · Aug 24, 2013 at 01:25 PM
This while loop will keep going until it is 90, then Update is over.
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.
Actually this wasnt exactly what I ment, but you gave me a good hint. The main problem was, that I used a while loop inside the Update function ins$$anonymous$$d of simply an if "loop". Thanks for your help.
Your answer
Follow this Question
Related Questions
Button in GUI BeginScrollView problem 0 Answers
Button and resolution problem 1 Answer
same background image and buttons to work with different apple devices 1 Answer
GUI Button sound problem, don´t work 1 Answer
Tooltip does not show 1 Answer