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 T27M · Oct 17, 2012 at 12:10 AM · c#guibool

Managing GUI Windows

Hello

I have a GUI menu with many buttons, when clicked the button sets a bool value and opens a new window, at the same time closing the previous window open. Currently I'm setting a lot of bools true or false on each click. I thought I might be able to do something like this:

 public void MenuManager(bool openWindow)
 {
     window1 = false; // Stop showing the window
     window2 = false;
     window3 = false;
    
     openWindow = true; // Show only this window , Could be any of the above windows
 }


The way I am going about it is to set all window bools to false, then set the window bool passed in to the method true to display the window. This results in all of the windows staying closed. Not as I expected, anyone have an idea as to why this is happening? or a suitable alternative.

Thanks

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 Mrobertson · Oct 17, 2012 at 01:29 AM

I believe your function isn't working because you are passing openWindow as a value, so this won't actually change the original variable, any changes you make to openWindow dont affect the variable you passed to MenuManager.

 public void MenuManager(ref bool openWindow)
 {
     window1 = false; // Stop showing the window
     window2 = false;
     window3 = false;
 
     openWindow = true; // Show only this window , Could be any of the above windows
 }

might make it work. Instead of using bools, i'd use a enumerator

 enum Windows {window1, window2, window3};
 Windows currentWindow = Windows.window1;
 
 public void OpenWindow(Windows w)
 {
 switch(w)
 {
 case Windows.window1:
 //open window 1 close other windows
 case Windows.window2:
 //open window 2 close other windows
 case Windows.window3:
 //openWindow 3 close other windows
 }
 }

another example of enumerations

 void OnGUI()
     {
         if(GUI.Button(new Rect(0,0, 10, 10), "Open Window 1"))
         {
             currentWindow = Windows.Window1;
             OpenWindow(currentWindow);
         }
         switch(currentWindow)
         {
         case Windows.NoWindows:
             //display gui for no windows
             break;
         case Windows.Window1:
             //display gui for Window1
             if(GUI.Button(new Rect(0,0,10,10), "Close Window Button"))
             {
                 currentState = Windows.NoWindows;
             }
             break;
             //........
         }
     }
Comment
Add comment · Show 3 · 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 T27M · Oct 17, 2012 at 12:45 PM 0
Share

Thanks for the reply. For the enumerator where does the Windows currentWindow variable come in to play do I have to set that as the active window? how do I use it as part of the code?

Could I just add a noWindows to the enum and set that as the default so no windows will be shown?

avatar image Mrobertson · Oct 17, 2012 at 01:34 PM 0
Share

Not knowing your project I can't be completely sure its the best solution, but from your code it looks like you only want one active window at a time so I think It would work alright. Yes you could just add a noWindows enum to the set for when no windows are shown. If you need more than one window state active at a time it might not be better.

I edited in a possible application of enumerations.

avatar image T27M · Oct 17, 2012 at 02:28 PM 0
Share

Ah I see. Its for a in game menu, I do only want one window open at a time as I want them all use the same positioning.

Your enum idea works great and saved me alot of time retyping out code.

Thanks again

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

10 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

Related Questions

Multiple Cars not working 1 Answer

One variable set TRUE when another must be false. TOGGLE 3 Answers

Using an Enum for GUI.Toggle? 1 Answer

Distribute terrain in zones 3 Answers

OnGUI sliders only accept float? C# 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