Search Unity

Destroy Gui Button

Discussion in 'Immediate Mode GUI (IMGUI)' started by Michele, Jun 27, 2008.

  1. Michele

    Michele

    Joined:
    Apr 28, 2008
    Posts:
    73
    Hi all,
    it's possible to destroy or hide some GUI.Button?

    This is my code, I would that when user click on the button it disappear.

    Code (csharp):
    1.  
    2.     if (GUI.Button (Rect (100,100,100,100), GUIContent ("",imgWiiMote, "WiiMote"))) {
    3.                 ....MyCode...
    4.         Application.LoadLevel(1);
    5.     }
    6.  
    Thanks in advance
     
  2. thomasvdb

    thomasvdb

    Joined:
    Feb 28, 2008
    Posts:
    85
    Not sure but maybe the enabled-property ?
     
  3. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    To hide buttons (or just gui stuff in general) simply just dont render the code which draws it.

    something like

    Code (csharp):
    1.  
    2.  
    3. bool bShowButton = true;
    4.  
    5. void OnGUI()
    6. {
    7.  
    8.  if(bShowButton){
    9.     if(GUI.Button(...) )
    10.     {
    11.        bShowButton = false;
    12.     }
    13.  }
    14.  
    15. }
    16.  
    if the buttons are in different OnGUI scripts you can use enabled.
     
  4. Michele

    Michele

    Joined:
    Apr 28, 2008
    Posts:
    73
    ahahah, right, I haven't though that possibility.
    Sometimes it is so easy :)

    Thanks
     
  5. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    This is the beauty of Unity GUI -- you can conditionally configure pretty much all GUI elements, as well as dynamically resize window containers, etc. on the fly.
     
  6. rh115

    rh115

    Joined:
    Nov 19, 2008
    Posts:
    81
    But I wonder the memory usage since the button is only disabled to render on GUI, will the resource of this button be released?

    Say, we have tons of buttons not to be rendered like this way, will it affect the performance of the game/machine?
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Nope. The button simply doesn't exist before or after your code is run - there are no resources to free.