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");
}
}
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;
}
}
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
Answer by ocolak54 · May 30, 2015 at 11:38 AM
and how to save this i dont want to see agaiın this button?
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
Your answer
Follow this Question
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