- Home /
GUI code causes strange GUISkin derived hiccup issues
function OnGUI(){
//GUI.Label (Rect (Screen.width-70, Screen.height-70, 90, 30), musicGameObject.audio.timeSamples.ToString());
GUI.Label (Rect (Screen.width-70, Screen.height-30, 30, 30), hiddenMeterHUD.ToString()+"%");
GUI.Label (Rect ((Screen.width-340)+(noticeMeter)*3, 18, 30, 30), Mathf.Round(noticeMeter).ToString()+"%");
GUI.skin=detectBarSkin;
GUI.Label (Rect (Screen.width-390, 0, 60, 30),"?!!");
GUI.Label (Rect (Screen.width-350, 10, (noticeMeter+10)*3, 10), " ", "button");
GUI.skin=null;
}
EDIT2:Other GUI code shows this problem as well , such as the one shown above.
EDIT: Here is where the hiccup lies in , i cant find the exact error im doing though
Answer by cjmarsh · Jan 06, 2011 at 02:53 AM
It seems to me that you have too much going on in this one OnGUI function. Every frame the entire OnGUI function is run through and I imagine that's causing your slowdown issues. You could separate the different menus into different scenes (Main, Options, New Game, etc.) and use Application.LoadLevel() to load each scene with it's own smaller, more condensed OnGUI function. Alternatively, you could create empty game objects with these menus attached, prefab them, and then instantiate and destroy them when you bring up the different menus. Whatever you do, just keeping down the number of operations performed every frame should help speed things up.
Edited the OP with some other code that shouldnt pose a problem but it does pose the exact same slowdown problem
Huh, that is very odd. I honestly have no idea what the problem is. $$anonymous$$aybe you should file a bug report and see if you can get a response? Sorry I couldn't be of more help.
Answer by Harald Scheirich · Apr 24, 2011 at 05:48 PM
You might be getting hit with garbage collection, every call to Rect() creates a new rect, and that every time OnGUI gets called. Try setting up these rects in Awake() or Start() and then just changing that values that need to change