Search Unity

Destroy OnGUI ()

Discussion in 'Immediate Mode GUI (IMGUI)' started by taragon, Oct 10, 2011.

  1. taragon

    taragon

    Joined:
    Jan 23, 2010
    Posts:
    119
    How can I get the last button in this code to disappear after say... 5-10 seconds? I tried yield and destroy(this), but they didn't work:
    Code (csharp):
    1. function OnGUI()
    2. {
    3.     if (npctrigger)
    4.     {
    5.     //GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
    6.    
    7.     if (yesbutton)
    8.     {
    9.         GUI.Box (Rect(0, 0, 100, 100), "Enter treasure chest");
    10.     }
    11.     else if (nobutton)
    12.     {
    13.         GUI.Box (Rect(0, 0, 100, 100), "You cannot enter");
    14.     }
    15.     else
    16.     {
    17.         GUI.Box (Rect(0, 0, 100, 100), "Give inventory?");
    18.         if (GUI.Button (Rect(25, 25, 50, 30), "Yes"))
    19.         {
    20.             yesbutton = true;
    21.             Debug.Log("True");
    22.         }
    23.  
    24.         if (GUI.Button (Rect(25, 65, 50, 30), "No"))
    25.         {
    26.             nobutton  = true;
    27.             Debug.Log("No");
    28.         }
    29.     }
    30.    
    31.     //GUI.EndGroup ();
    32.     }
    33. }
    34.  
    35.  
     
  2. Eiznek

    Eiznek

    Joined:
    Jun 9, 2011
    Posts:
    374
    Just have a boolean like all your others.. Make it switch after 5 seconds. Put the button into an if{ } block..