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 missypooh · Mar 25, 2012 at 05:27 AM · scriptingbasicsongui

Why button is not display the window

 function OnGUI()
 {
     if(GUI.Button(Rect(190,14,110,40), "Use Diamonds"))
     {
         use = true;
     }
     
     if(use)
     {
         GUI.Window(0, Rect((Screen.width/2)-230, (Screen.height/2)-255, 330, 260), useMagic, "Special Request");
     }
     
     //GUI.Button(Rect(300,14,110,40), "Minimap toggle");
     
 }
 
 function useMagic()
 {
     if(use)
     {
         print("display diamond");
         GUI.Button(Rect(40,44,90,120), greenDiamond, "");
         GUI.Label (Rect (100, 44, 300, 60), " X " + collectgreenDiamond);
         GUI.Button(Rect(40,104,100,120), purpleDiamond, "");
         GUI.Label (Rect (100, 104, 300, 60), " X " + collectpurpleDiamond);
     }
     // You may put a button to close the pop up too 
     if (GUI.Button(Rect(40, 180, 75, 30), "Close"))
     {
         use = false;
     

} } Anyone can tell me what wrong with the code snippet?? When i click on use diamond, it is not displaying the window?? I can't seem to see anything wrong..

*EDIT: i have update my code snippet. Now the window is display but another thing that make me headache is. HOw come the window is not closed?? what wrong??

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
2

Answer by farooqaaa · Mar 25, 2012 at 07:59 AM

You should use a boolean variable and set it to true or false whether you want to show the window or hide it:

 var drawWindow : boolean;

 function OnGUI()
 {
     if(GUI.Button(Rect(190,14,110,40), "Use Diamonds"))
     {
         drawWindow = true;
         use = true;
     }
 
     if(drawWindow)
     {
         GUI.Window(0, Rect((Screen.width/2)-320, (Screen.height/2)-260, 660,260), useMagic, "Special Request");
     }

     GUI.Button(Rect(300,14,110,40), "Minimap toggle");
 }
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 missypooh · Mar 25, 2012 at 09:18 AM 0
Share

hello. thank you for the reply. I have update my code snippet. Now the window can display. but i can't seem to close the window..

avatar image You! · Mar 25, 2012 at 09:28 AM 0
Share

You cannot use GUI outside of the OnGUI() function. Put your "close" GUI inside the same "if" statement as the window.

avatar image hijinxbassist · Mar 25, 2012 at 09:47 AM 1
Share

@You You are suppose to be able to have GUI inside of the windows...if you take a glance at the reference

avatar image
0

Answer by hijinxbassist · Jun 09, 2012 at 08:11 AM

So the answer here CAN be found in the ref. I did my first real gui window tonight(im sure you already figured it out by now, being this question is from quite a while ago).

The function NEEDS the id as the overload(seems like that should be handled in the Unity Source Code, ne way). Heres my slimmed down version

 function OnGUI()
 {
     if(GUI.Button(Rect(190,14,110,40), "Use Diamonds")) use=true;
     if(use)
        GUI.Window(0, aRect, useMagic, "Special Request");
 }
 
 function useMagic(ID:int)
 {
     if(ID==0)
     {
         //MAGIC COMMAND WITH ID OF " 0 "
         //This is where the gui stuff goes
         //Like buttons and whatnot
     }
 }

If you are using this same function for multiple cases(more than 2) then use a switch case(search 'switch case'). Sorry @missypooh for taking soooooo long to get you a good answer to this, came across this old ques doing my own search for an unrelated question. This is to help future searchers, as im sure you are way past this :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Project Scripting - Tracking variables (General Question) 2 Answers

How Do You Parent an Object With Scripts? 1 Answer

What does the word for mean in javascript? 1 Answer

Zoom in and zoom out of minimap 5 Answers

Change variable of instantiated object from different game Objects 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