- Home /
GUI Button to create another GUI
Trying to create a gui system. If you press image2 button i want another gui box and buttons to pop up asking to drop something. heres the code:
 function OnGUI() {
 
 var activateSubMenu = false;
 
 inventoryStyle.normal.background = guiBackground;
 
     if(iWasPressed && timesPressed == 1)
     {
         Time.timeScale = 0;
         inventoryOpen = true;
         GUI.Box(Rect(guiX, guiY, guiWidth, guiHeight), "inventory", inventoryStyle);
         if(GUI.Button(Rect(15,30,75,75), slot1))
         {
             Instantiate(Resources.Load(deployObject.name), Vector3(transform.position.x, transform.position.y, transform.position.z + 5),
             Quaternion.identity);
             GUI.Box(Rect(Screen.width/2, Screen.height/2, 150, 150), "drop object?");
             if(GUI.Button(Rect(Screen.width/2, Screen.height/2 + 5, 50,50), "Yes"))
             {
             
             }
             
             if(GUI.Button(Rect(Screen.width/2, Screen.height/2 + 5, 50,50), "No"))
             {
             
             }
         }
         if(GUI.Button(Rect(160,30,75,75), slot2))
         {
             activateSubMenu = true;
         }
         
         if(activateSubMenu == true)
         {
             Debug.Log("clicked image2");
             GUI.Box(Rect(0, 0, Screen.width, Screen.height), "drop object?");
             if(GUI.Button(Rect(0, 0, 50,50), "Yes"))
             {
             
             }
             
             if(GUI.Button(Rect(0, 0, 50,50), "No"))
             {
             
             }
         }    
     }
     
     if(timesPressed < 1 | timesPressed > 1)
     {
         inventoryOpen = false;
         Time.timeScale = 1;
     }
 
 }
 
 function ObjectImage() {
 
 if(selectedObject.name == "testObject1")
 {
     slot1 = testImage;
     if(slot1 == testImage)
     {
         Debug.Log("slot1 should be test image");
     }
     deployObject = gameObject.Find("testObject1");
 }
 
 if(selectedObject.name == "testObject2")
 {
     slot1 = testImage2;
     deployObject = gameObject.Find("testObject2");
 }
 
 }
 
 if(!slot1)
 {
     slot1 = defaultImage; 
 }
the problem is inside the Gui button with the text image and image 2. when i click those buttons, the buttons and box thats suppose to come after wont show. any pointers?
Answer by DaveA · Jan 19, 2012 at 12:10 AM
It probably shows it for 1 frame, as 'if (GUI.Button... ' happens in one frame.
You should set some boolean that says that the button is hit, then check that boolean to conditionally display the other stuff.
 var subMenu = false;
 
 OnGUI()
 ...
 
  if (GUI.Button ...
    subMenu = true;
  if (subMenu)
  {
    if (GUI.Button.... // the sub-menu button
and have a way to set subMenu = false to erase it from the screen
its not working... im guessing because it returns false once the button isnt clicked anymore.. im not sure. i updated the code take a look please.
never$$anonymous$$d i accidently set the boolean within the gui. THAN$$anonymous$$S
Your answer
 
 
             Follow this Question
Related Questions
Button being pressed but an other button gets the effect. 0 Answers
GUI grid of buttons issue. 1 Answer
button wont work in GUI.BeginScrollView 0 Answers
GUISkin is overlaying my button image 0 Answers
proper inventory system issue.. 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                