- Home /
ReScaling with easing?!
Hello, I use a piece of code that is supposed to enlarge a small tab in a larger area of information (all hover). The code works but also by reducing the value of magnification tab moves from position to position "unfolded" instantly ... GUI does not run to the enterFrame?
private float _Wacceuil = 40;//valeurs références par défaut
private float _Hacceuil = 50;
private float _WacceuilOFF = 40;//valeurs références d'origines, position plié
private float _HacceuilOFF = 50;
private float _WacceuilON = 100;//valeurs références d'origines, position déplié
private float _HacceuilON = 250;
GUI.Button(new Rect(0, 60, _Wacceuil, _Hacceuil), "Acceuil");
if (Input.mousePosition.x>0&&Input.mousePosition.y<Screen.height-60 &&
Input.mousePosition.x<0+_Wacceuil &&
Input.mousePosition.y>Screen.height-60-_Hacceuil)
{
while(_Wacceuil < _WacceuilON)
{
_Wacceuil += .1f;
}
while(_Hacceuil < _HacceuilON)
{
_Hacceuil += .1ff;
}
}
else
{
if(_Wacceuil > _WacceuilOFF)
{
while(_Wacceuil > _WacceuilOFF)
{
_Wacceuil -= .1f;
}
}
if(_Hacceuil > _HacceuilOFF)
{
while(_Hacceuil > _HacceuilOFF)
{
_Hacceuil -= .1f;
}
}
}
while loops inside of repeated functions will execute instantly! You should put all of this logic inside a coroutine, and run that ins$$anonymous$$d, using
yield return null;
in between executions.
I'd give you a code example, but I'm pressed for time- I'm sure one of the other helpful folks here will be able to solve this one.
Answer by DaveA · Nov 04, 2011 at 11:20 PM
Change all these 'while' statements, like
while(_Wacceuil < _WacceuilON)
to 'if' statements like
if (_Wacceuil < _WacceuilON)
I assume this is all in an OnGUI function, which it should not be. Move it to an Update function, except for the GUI.Button line
Your answer
Follow this Question
Related Questions
Is this the correct way to scale my GUI? 1 Answer
Unity3d GUI Element Scaling 1 Answer
GUI scaling on mobile 1 Answer
UI Constant Physical Size, rect sizes not corresponding to real sizes 0 Answers
Interface relative scaling 0 Answers