• 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
Question by AfricanMoney · Apr 08, 2013 at 08:25 AM · guibuttondestroymenuupgrade

How do I destroy a GUI button when I click on it

I am making a upgrade menu. All I want to know is how do I destroy a GUI button when I click on it. So when I buy a spell the button gets destroyed so that I cant buy it again.

Comment

People who like this

0 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 bkevelham · Apr 08, 2013 at 08:27 AM 0
Share

Maintain some form of state whether or not it has been click. And if so, simply don't draw it again in the Update.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by RyanZimmerman87 · Apr 08, 2013 at 08:28 AM

Well it depends on how your project is coded. But generally I don't destroy any GUI buttons I would just hide it. So in your case I'd probably use some if(condition) to show the button, and once you click it that condition no longer applies. And then you would need some code to reconfigure your menu if there's more buttons that are supposed to take it's place.

It could be a very simple or somewhat complex solution depending on exactly what you are trying to do.

So I guess I'll add a brief example in case it helps:

 public Texture2D healthPotionTexture;

 public GUIStyle GUIStyleButton;
 
 bool buttonPressedBool = false;
 
 void OnGUI()
 {
 
   if (buttonPressedBool == false)
   {
     //healthPotionTexture is the name of the texture used to display button (can be .PNG for example)

     //GUIStyleButton will make the button appear without any borders


     if (GUI.Button (new Rect (vectorPosition.x, vectorPosition.y, vectorSize.x, vectorSize.y), healthPotionTexture, GUIStyleButton))
     {
     //what the button does...
 
        buttonPressedBool = true;
     }
  }
 }
Comment
Loius

People who like this

1 Show 0 · 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

GUI Buttons not working after scene transition 0 Answers

Load, Save and Options Gui Help 1 Answer

How do I use my .png file as a button? 1 Answer

Sound to play when clicking buttons on GUI 1 Answer

My GUI buttons are triggering without user input. 1 Answer


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