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 GenericUsername_1004 · Apr 06, 2012 at 10:02 AM · guiobjectwindowhowdraw

How do I make GUI buttons draw more GUI objects when clicked?

A while ago I made the code for a GUI menu which I unfortunately lost, so I've had to start again. This time though, I'm using the GUI.Window system, which I hadn't noticed before (previously I'd used Boxes). However when running the program either in the Editor or as a standalone, only the Quit button is drawn. If I click that, the appropriate Debug messages appear, but it doesn't seem to draw the Windows. So how can I get this to work properly? The answer's probably staring me in the face, but I'd really appreciate an answer.

Code:

 #pragma strict

 var miniWindowDimensions : Rect = Rect((Screen.width/2)-(Screen.width/10),(Screen.height/2)-(Screen.height/10),Screen.width/5,Screen.height/5);
 public var close : Texture;
 public var freezeLayerOne : boolean = false;
 function OnGUI()
 {
     if(GUI.Button(Rect(Screen.width*0.6, (Screen.height/20)*18, Screen.width/3, Screen.height/10), "QUIT") && freezeLayerOne == false)
     {
         print("Quit pressed");
         freezeLayerOne = true;
         GUI.Window(0,Rect(miniWindowDimensions),sureQuitCreate,"Are you sure?");
     }
 }
 
 function sureQuitCreate(windowID : int)
 {
     if(GUI.Button(Rect((Screen.width/2)+(Screen.width/20)*15,(Screen.height/2)-(Screen.height/10)+2,20,20),close))
     {
         freezeLayerOne = false;
         print(freezeLayerOne);
     }
     if(GUI.Button(Rect(0,0,40,40),"QUIT"))
     {
         Application.Quit();
     }
 }
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 Kleptomaniac · Apr 06, 2012 at 12:07 PM

I have absolutely no idea why this doesn't work, but I managed to get it to work by using a boolean and then checking its state and rendering on the condition that it's true. So like this:

 #pragma strict
 
 var miniWindowDimensions : Rect = Rect((Screen.width/2)-(Screen.width/10),(Screen.height/2)-(Screen.height/10),Screen.width/5,Screen.height/5);
 public var close : Texture;
 public var freezeLayerOne : boolean = false;
 var canRenderWindow : boolean = false;
 
 function OnGUI()
 {
     if(GUI.Button(Rect(Screen.width*0.6, (Screen.height/20)*18, Screen.width/3, Screen.height/10), "QUIT") && freezeLayerOne == false)
     {
        print("Quit pressed");
        freezeLayerOne = true;
        canRenderWindow = true;
     }
     
     if(canRenderWindow) {
         miniWindowDimensions = GUI.Window(0,Rect(miniWindowDimensions),sureQuitCreate,"Are you sure?");
     }
 }
 
 function sureQuitCreate(windowID : int)
 {
     if(GUI.Button(Rect((Screen.width/2)+(Screen.width/20)*15,(Screen.height/2)-(Screen.height/10)+2,20,20),close))
     {
        freezeLayerOne = false;
        canRenderWindow = false;
        print(freezeLayerOne);
     }
     if(GUI.Button(Rect(0,0,40,40),"QUIT"))
     {
        Application.Quit();
     }
 }

Hope that helps! Klep

Comment
Add comment · 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 GenericUsername_1004 · Apr 06, 2012 at 07:20 PM 0
Share

Thanks, but for me, this just renders a small rectangle at the top of the screen. Do you think there's a problem with my copy of Unity?

avatar image Kleptomaniac · Apr 07, 2012 at 07:14 AM 0
Share

No, it did that for me as well. I'd say it's something to do with your GUI.Window code, but I've never worked with them before, so I wouldn't know. Hmm, possibly try taking the Rect() out of

  $$anonymous$$iWindowDimensions = GUI.Window(0,Rect($$anonymous$$iWindowDimensions),sureQuitCreate,"Are you sure?");

because you are already declaring $$anonymous$$iWindowDimensions as a Rect. Also possibly trying playing around with your width and height parameters of $$anonymous$$iWindowDimensions. Other than that, I can't help you ...

$$anonymous$$lep

avatar image
0

Answer by GenericUsername_1004 · Apr 11, 2012 at 06:29 PM

Thanks very much Klep.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUI draws only one window at a time 1 Answer

Windows that do not take priority over other GUI elements 0 Answers

GUI Window Render Priority 1 Answer

touch 3d object open gui 1 Answer

ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint 0 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