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 /
  • Help Room /
avatar image
0
Question by Brent Gilson · Oct 09, 2013 at 07:55 PM · gui.button

How do I destroy a GUI.button after it is clicked?

I want the "Options" and "kenney" buttons to be deleted after they're clicked once. I already tried: Destroy(GUI.buttion); and other things along the lines of that, but it won't work. here's my javascript:

var target : GameObject; function OnGUI () { // Make a background box GUI.Box (Rect (Screen.width -300,5,250,230), "Main Menu");

 // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
 if (GUI.Button (Rect (Screen.width - 250,40,160,40), "Start Game")) {
     Application.LoadLevel (1);
 }

 // Make the second button.
 if (GUI.Button (Rect (Screen.width - 250,100,160,40), "Credits")) {
     print("Credits!");
     Application.LoadLevel (2);
 }
 if(GUI.Button(Rect(Screen.width - 250,160,160,40), "Options")) {
     print("Options");    
     animation.Play("Options");
 }
 
 //hidden button
 if(GUI.Button(Rect(Screen.width - 1920,890,20,20), "kenney")) {
     print("kenney");
     target = GameObject.Find("kenney");
     target.animation.Play("easteregg");
     
 }    

}

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

4 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by clunk47 · Oct 09, 2013 at 08:15 PM

 #pragma strict
 
 private var showButton : boolean = true;
 
 function OnGUI()
 {
     if(showButton)
     {
         if(GUI.Button(Rect(0, 0, 128, 128), "Click me!"))
             showButton = false;
     }
 }
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 MarkD · Oct 09, 2013 at 08:09 PM

It is very simpel, you can't realy delete a button, but you can 'hide' it. At least that is how I always do it. Simply make a boolean variable for the button you want to hide: example:

     var ButtonClicked:Boolean=false;
         
         
         if(GUI.Button(Rect(Screen.width - 250,160,160,40), "Options")&& ButtonClicked==false) {
             print("Options");  
             animation.Play("Options");
         ButtonClicked=true;
         }

The GUI will simply stop drawing a button if the acces to it is denied. You can do this for every button, and if you think your editor gets messy of all the bools simply make them private.

Greetings

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 ocolak54 · May 30, 2015 at 11:38 AM

and how to save this i dont want to see agaiın this button?

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 Ahma_d0007 · Oct 01, 2015 at 12:06 PM

Its really bad to do hide it cost alot to gpu and cpu do something with culling

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why isn't WaitForSeconds working? 1 Answer

How to make enemy chase player. Basic AI 7 Answers

How to Make a simple GUI using unity C# and Kinect 0 Answers

need help i have my mod for a game and im trying to make two of my gui.buttons work off a keybind 1 Answer

How to create an if statement for each element within a list 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