I’m trying to open a new GUI from a GUI button. Mine doesn’t work and I’m not sure why. I even looked at another similar post but still couldn’t fix it. Here’s a snippet of code:
var showMenu : boolean = false;
function OnGUI() {
//this function is used to hide the toggle icon.
if(!showMenu) {
showMenu = GUI.Toggle(Rect(10, 10, 32, 32), showMenu, "", "toggleMenu");
}
//menu code
if(showMenu) {
GUI.Box (Rect (20,30,280,402), "", "menuBG");
GUILayout.BeginArea(Rect(ScreenX, ScreenY, areaWidth, areaHeight));
if(GUILayout.Button("", "buttonHow"))
{
howtoMenu();
}
GUILayout.EndArea();
}
}
function howtoMenu() {
print("in sub menu")
GUI.Box(Rect(15, 5, 260, 200),"", "submenuBG");
GUILayout.BeginArea(Rect(50, 10, 260, 200));
GUILayout.EndArea();
}
I’m not sure why but it’s not even showing the “submenuBG” texture. Basically I have a main menu and a submenu. I’d like to open the menu, click on the how to button that will disable the menu and open the sub menu. Once I close the submenu, I’d like to go back to the main menu. Hope that makes sense. I really need help on this one.
Thanks for the reply. I managed to draw a separate UI now :P. I forgot to arrange the order of where it should draw. Initially, I made the function to draw the menu outside of the OnGUI Scope. After putting it inside I was able to draw the submenu. Now I just need to write it so when the submenu is opened, the main menu is hidden is the app still in pause mode.
Not sure how, but is there a way to debug a GUI in iPhone? The one I have keeps crashing/hanging when I:
click on button > opens main menu > click on button > show How to Menu(hides main menu).
From the show how to menu, I’ve made a button that can exit to main menu. That’s when it hanged. Not sure how to debug it since I can’t tell if it;s using that much memory or anything.
Only after I change the size from 30x30 to 80 x 80 in code for the buttonClose that it doesn’t crash. However, it still lags in terms of input. Takes a second-ish to close the submenus.
Not sure what you meant when you said UI can’t draw if I’m locking the player? How am I locking the player? The disObject function basically set the .active of other gameObjects in the scene to false e.g.
myArea.active = false;
I actually have it in the main menu as well and it doesn’t slow down. Instead of making the function, should I put it inside the GUIayout.Buttons’s scope?
All of them? Can you post the code for this function too? It could be CPU-intensive, depending on how it is structured. If the same objects are redundantly disabled each frame, you should probably just call this once when it is first needed.
Basically I’m using this method because I use these gameobjects to detect collision for certain areas. It’s basically used when I pause my app. When I unpause it, they’re basically set bact to “false”.