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 HolBol · Nov 22, 2011 at 10:01 PM · javascriptguibuttononmousedowndisappear

Hide/show GUI Buion

I'm writing a script that when a person clicks a GUI button , it then disappears. How can I do this?

My GUI Code is this.

 function OnGUI () {
     GUI.skin = theme;
 
     
     GUI.BeginGroup (new Rect (Screen.width / 2 - 320, Screen.height / 2 - 240, 640, 480));
 
         if (GUI.Button (Rect (10,30,620,30), button1text)) {
             print("You clicked 1");
             response = answer1;
         }
     GUI.EndGroup();
    }


How can I get that button to disappear until the next time the script is activated? So it's unclickable, not even visible, even. Any ideas?

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
3
Best Answer

Answer by jahroy · Nov 22, 2011 at 10:13 PM

This will draw a button until the button gets clicked.

You will have to use another script, a button, a timer, or something else to turn it back on.

All you would have to do is set isButtonVisible to true again...

var isButtonVisible : boolean = true; var buttonRectangle : Rect = Rect(100, 100, 100, 50);

function OnGUI () { / only draw the button if isButtonVisible equals true /

 if ( isButtonVisible ) {
     if ( GUI.Button(buttonRectangle, "Turn Me Off") ) {
         isButtonVisible = false;
     }
 }

}

Comment
Add comment · Show 5 · 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 HolBol · Nov 22, 2011 at 10:17 PM 0
Share

Thanks- sorry, had a dumb moment. Booleans are the way forward!

avatar image jahroy · Nov 22, 2011 at 11:26 PM 0
Share

Have you been spending too much time playing the vacuum cleaner again?

avatar image HolBol · Nov 22, 2011 at 11:29 PM 0
Share

....? I shall not ask XD

avatar image jahroy · Nov 23, 2011 at 12:38 AM 0
Share

Sorry... Figured you were a Phish fan based on your screen name.

avatar image alee26 · Aug 26, 2012 at 02:19 PM 0
Share

Thanks for the tip.

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

how to make a button call another button and then disappear 1 Answer

Make button clickable 2 Answers

Touch Control Android Java 0 Answers

Can't get 4.6 GUI Button to Load Scene (Solved) 1 Answer

Select a game object and perform actions using GUI.Button (EventTrigger) 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