• 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
0
Question by $$anonymous$$ · Jul 15, 2013 at 01:30 AM · mainmenu

Bring Up Another GUI Box With Buttons When A Button Is Clicked?

Hey Guys

Im working on a small horror game at the moment based off the anime, Hetalia and im having trouble with the main menu. See it has 3 buttons. One to start the game. One to exit and one thats a level select. When i click the level select i want it to bring up a new GUI box next to the main menu gui and display the levels. But so far. It doesnt draw the box when i click the level select or bring up the new buttons!

Here IS My Code

 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 // JavaScript
 function OnGUI () {
     // Make a background box
     GUI.Box (Rect (350,100,200,100), "Canada's Nightmare");
     GUI.Box (Rect (150,100,200,100), "Choose Your Nightmare");
     // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
     if (GUI.Button (Rect (350,120,200,20), "Enter The Nightmare")) {
         Application.LoadLevel (1);
     }
     if (GUI.Button (Rect (350,150,200,20), "Choose The Nightmare")) { // Level Select begins
         
            if (GUI.Button (Rect (150,130,200,90), "Britains Coal Mines")) {
            Application.LoadLevel (1);
            } 
            
            if (GUI.Button (Rect (150,160,200,90), "No Level Here")){
            
            }
     } // Level Select Ends
     
     if (GUI.Button (Rect (350,180,200,20), "Wake Up...")) {
         Application.Quit();
     }
 }

Thanks in advance!

Comment
Add comment
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
0
Best Answer

Answer by Cerbion_ · Jul 15, 2013 at 01:37 AM

The problem you're facing is simple: pressing a GUI.Button in unity only calls the function within the brackets >ONCE< meaning, it's showing for a single frame and disappears. However there's a common workaround for that, just assign a new variable which is set to TRUE whenever someone clicks on the button and as long as it's true the button are shown, otherwise not

for example

  var ShowOtherGUIElements : bool; //true = show the other GUI elements


and then in your OnGUI()

 if(ShowOtherGUIElements)
 {
 //your new buttons/GUI elements here
 }


I hope that helped you out ;)

Comment
Add comment · Show 1 · 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 $$anonymous$$ · Jul 15, 2013 at 01:48 AM 0
Share

Worked Flawlessly. Thank you very much!

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

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

How can I add a UI (Main Menu) with function. 0 Answers

i made a script called pause menu.when someone click on main menu option it sents to the main menu.The script works perfectly but on main menu the options start and quit game are not responding.help me.here's the script. 1 Answer

GUI is not function correctly when using 'Application.LoadLevel' in C#. 1 Answer

Can't go back to the game scene from main menu for the second time 2 Answers


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