Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 ab_cee · May 25, 2010 at 11:21 AM · javascriptguiguilayoutgui.button

Open gui if player clicks on button

i want to open another gui if the player clicks a gui button.

so .. if the player clicks on my third button it should open/enable a new gui window

this is my code so far

function OnGUI () { // Make a background box GUI.Box (Rect (10,10,100,120), "Menu");

// Button 1: Make the first button. If it is pressed, Application.Loadlevel (1) will be executed if (GUI.Button (Rect (20,40,80,20), "Restart")) { Application.LoadLevel ("Level 1"); }

// Button 2: Make the second button. if (GUI.Button (Rect (20,70,80,20), "Main Menu")) { Application.LoadLevel ("Level 2"); }

//Button 3: make third button here should be the button to make a new gui??? if (GUI.Button (Rect (20,100,80,20), "Info")) {

} }

should a make a new script with the new gui i want to activatie, and activatie/enable it if player clicks on button 3 somehow?

or is there a much easier way?

greetingz, ab_cee

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ab_cee · May 25, 2010 at 12:11 PM

Just got the code from nicholas on the unity forums:

Code:

var showMoreGui = false;

function OnGUI () { if (GUI.Button (Rect (10,10,100,20), "Show More")) showMoreGui = true;

 if (showMoreGui) { 
     GUI.Button (Rect (10, 40,100,20), "Hello there"); 
     if (GUI.Button (Rect (10, 70,100,20), "Close")) 
         showMoreGui = false; 
 } 

}

To seperate it out a bit, you could do: Code:

var showMoreGui = false;

function OnGUI () { if (GUI.Button (Rect (10,10,100,20), "Show More")) showMoreGui = true;

 if (showMoreGui) 
     ExtraGUI (); 

}

function ExtraGUI () { GUI.Button (Rect (10, 40,100,20), "Hello there"); if (GUI.Button (Rect (10, 70,100,20), "Close")) showMoreGui = false; }

Whether you want to split out this more GUI or do it like this generally depends on the complexity. I usually start with just having it inline, then move it to a separate function before completely splitting it out.

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

Answer by StephanK · May 25, 2010 at 12:11 PM

Depending on the complexity of your GUI it might be a good idea to have several GUI scripts, that get switched. However what I tend to do on non-complex GUI's is this:

int menuNumber = 0;

void OnGUI() { switch(menuNumber) { case 0: DisplayMainMenu(); break; case 1: DisplayOtherMenu(); break; default: break; }

void DisplayMainMenu() { if (GUI.Button(rect, "Change Menu")) menuNumber = 1; }

void DisplayOtherMenu() { if (GUI.Button(rect, "Change Menu")) menuNumber = 0; }

I hope this gives you an idea.

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 ab_cee · May 25, 2010 at 12:23 PM 0
Share

oke thanks spree , i'll try that too. It needs to be a new gui with photo's(2d textures) and maybe video's.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

GUI.Button toggling object visibility. 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Reverse GUILayout 1 Answer

For Loop GUILayout.Label Problems 1 Answer

Need help using GUI.Button/ input storage 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