Self Destruct

How do you have a button remove itself after use? When clicked an action is performed and the button is no longer needed.

Thanks,
r.b

what i do is create a empty game object name it button assign the button script to it create a variable and then add a bit of code like

button.gameObject.active = false;

you have to remember to make the boollean true at start in a separate script.

How are you displaying your button? If it’s being shown via GUI.Button() then you can have a variable that is checked and either draws the button or not:

// Untested forum code
var ShowButton = true;

function OnGUI () {

  if (ShowButton) {
    if (GUI.Button(Rect(...), "Hello")) { 
      // Do something here...
      ShowButton = false;
    }
  }

}

Alternatively you can have a script with your OnGUI code attached to a separate and unique game object and then do as recommended above (disable the game object) as that will also “hide” the button from view.

Excellent, that’s exactly what I needed. The only difference to how I actually implemented it, the flag is set elsewhere.

r.b