- Home /
Custom GUI.Box function dilemma
I wanted to created a special GUI.Box() function, called _BOX().
What it would do is that instead of having a box appear, it would have it's own fancy animation that would resize itself automatically, basically how the pop up windows work in Super Mario World.
The problem is that the function needs to repeatedly resize itself, but now that the function would be called in OnGUI(), an UPDATE function, it would cause super-lag.
function _BOX(rect:Rect,s:String){
GUI.Box(rect,s);
//see? to put a 'for' loop right here would cause massive lag,
//due to the fact that this function will be called in an OnGUI, but not doing so only results in the GUI box to just resize by one pixel.
//i do not want to have two variables outside of this function either, it's not too efficient as i will call this _BOX function many times
rect.width += 1;
rect.height += 1;
}
function OnGUI(){
_BOX(new RectC(200,100),"Hello World!"); //ignore my RectC function
}
Answer by YoungDeveloper · Oct 19, 2013 at 05:05 PM
Loops which are not very long (talking about tens of thousands of lines) is not that bad in update or ongui. If you think about what basically is for or other loop, it is an instructed way do to things many times. So here's an example in code, these two examples are almost the same, "almost" because for for loop it will need extra i variable and two small operations: i++ and check if i>5, which are checked only once before each instance of loop.
//This isn't that bad, right ?
OnGUI(){
Debug.Log("print message operation");
Debug.Log("print message operation");
Debug.Log("print message operation");
Debug.Log("print message operation");
}
//So why should be bad ? But this will use a tiny bit more resources, as i mentioned
OnGUI(){
for(int i = 0;i < 5; i++){
Debug.Log("print message operation");
}
}
Your answer
Follow this Question
Related Questions
GUI box problem? 0 Answers
my GUI.box is transparent 1 Answer
Where is my HP Bar? 3 Answers
Applying a script to multiple gui boxes 0 Answers
Strange behaviour GUI.Box 1 Answer