- Home /
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.
$$anonymous$$aintain some form of state whether or not it has been click. And if so, simply don't draw it again in the Update.
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;
}
}
}
Your answer
Follow this Question
Related Questions
How do I use my .png file as a button? 1 Answer
My GUI buttons are triggering without user input. 1 Answer
Sound to play when clicking buttons on GUI 1 Answer
GUI destroy instantiated Objects 2 Answers
Animate GUI Elements 1 Answer