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 kenkennet20 · Jul 15, 2012 at 03:17 PM · buttontogglewindowshowinghiding

Hiding/Showing window on button

I've tried many things, but I can't get this javascript to work. I've got a hotbar with some buttons init, and I want to create another rect window, and have one of the buttons in the hotbar, open and close this window for the player.

Comment
Add comment · Show 1
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 Piflik · Jul 15, 2012 at 03:25 PM 0
Share

Can you show us your current script?

Essentially you need a boolean variable that you toggle with one button and test for it in the code for the window via an if statement.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kenkennet20 · Jul 15, 2012 at 08:31 PM

 var Interface_Hotbar_Window = Rect(0, 0, 265, 50);
 
 var Interface_01_Window = Rect(100, 100, 200, 200);
 
 var Interface_Hotbar_Image_01 : Texture;
 var Interface_Hotbar_Image_02 : Texture; 
 var Interface_Hotbar_Image_03 : Texture; 
 var Interface_Hotbar_Image_04 : Texture; 
 var Interface_Hotbar_Image_05 : Texture; 
 var Interface_Hotbar_Image_06 : Texture; 
 
 
 
 function OnGUI ()
 {
     
     Interface_Hotbar_Window = GUI.Window (0, Interface_Hotbar_Window, Interface_Hotbar_Settings, "");
     Interface_01_Window = GUI.Window (1, Interface_01_Window, Interface_01_Settings, "");
     
 }
 
 
       
 function Interface_Hotbar_Settings (windowID : int)
 {
 
  if (GUI.Button(Rect(5,5,40,40),Interface_Hotbar_Image_01));
  // Not implemented.
  
  if (GUI.Button(Rect(48,5,40,40),Interface_Hotbar_Image_02));
  // Not implemented.
  
  if (GUI.Button(Rect(91,5,40,40),Interface_Hotbar_Image_03));
  // Not implemented.
  
  if (GUI.Button(Rect(134,5,40,40),Interface_Hotbar_Image_04));
  // Not implemented.
  
  if (GUI.Button(Rect(177,5,40,40),Interface_Hotbar_Image_05));
  // Not implemented.
  
  if (GUI.Button(Rect(220,5,40,40),Interface_Hotbar_Image_06))
  {
      Application.Quit();
  }
  
  
     GUI.DragWindow ();
 
 }
 
 
 
 
 function Interface_01_Settings (windowID : int)
 {
 
     GUI.DragWindow ();
 
 }
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
Wiki

Answer by Jixi · Jul 15, 2012 at 11:18 PM

Here's how i would do it in c#(should be easy enough to convert it into js)

  bool hideWindow = true;
     
     void OnGUI()
     {
         if(GUI.Button(new Rect(30, 30, 100, 100), "Button"))
         {
            //When button is pressed it toggles the hideWindow boolean
            if(hideWindow) hideWindow = false;
            else hideWindow = true;
         }
     
         if(hideWindow)
         {
         //Your window code here
         }
     
     }
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

Answer by kenkennet20 · Jul 16, 2012 at 02:49 PM

Thanks a lot, it works almost fine, converted to JavaScript, but how do I reference to a window outside my rect. I mean, I created the buttons inside a rect, so the bar can be moved around, but this also means that if I do it this way, the window that I open, will be put inside this little area too. How do I make a window outside of this confined Interface_hotbar_settings, and have the true/false thing show/hide that window, outside?

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

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

6 People are following this question.

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

Related Questions

How to reset the state of other buttons when clicking on one of them 0 Answers

UI Button should stay highlighted on click 2 Answers

Open window on button click 1 Answer

Toggle Button Question 0 Answers

Animation window not showing list of animations, even if i click on the object 9 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