• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Kag359six · Jan 18, 2012 at 11:01 PM · guibuttoninventorysequence

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?

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

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

Comment
jahroy
Kag359six

People who like this

2 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kag359six · Jan 19, 2012 at 04:43 PM 0
Share

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.

avatar image Kag359six · Jan 19, 2012 at 05:29 PM 0
Share

nevermind i accidently set the boolean within the gui. THANKS

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges