Search Unity

Two GUI popups - 1st one needs to be destroyed

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

  1. taragon

    taragon

    Joined:
    Jan 23, 2010
    Posts:
    119
    I have 2 GUI popups, one followed by the other. The problem is that after the first one comes up and the player selects either "yes" or "no", the 2nd pop-up occurs... the first one is never destroyed, and I'm not sure how to correct this. Here is the code... it's attached to the enemy robot in the 3dplatformertutorial script, "EnemyPoliceGuy.js"
    Code (csharp):
    1. function OnGUI() {
    2.     GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
    3.    
    4.     GUI.Box (Rect(0, 0, 100, 100), "Give inventory?");
    5.         if (GUI.Button (Rect(25, 25, 50, 30), "Yes")){
    6.             yesbutton = true;
    7.             Debug.Log("True");
    8.             }
    9.  
    10.         if (GUI.Button (Rect(25, 65, 50, 30), "No")){
    11.             nobutton = true;
    12.             Debug.Log("No");
    13.             }
    14.        
    15.     if (yesbutton == true){
    16.         GUI.Box (Rect(0, 0, 100, 100), "Enter treasure chest");
    17.         }
    18.     else
    19.         return;
    20.     if (nobutton == true){
    21.         GUI.Box (Rect(0, 0, 100, 100), "You cannot enter");
    22.         }
    23.     else
    24.         return;
    25.    
    26.     GUI.EndGroup ();
    27. }