Search Unity

does anyone know how to remove a gui.box after pressing a key?

Discussion in 'Immediate Mode GUI (IMGUI)' started by JUANK7323, Mar 31, 2022.

  1. JUANK7323

    JUANK7323

    Joined:
    Mar 23, 2022
    Posts:
    1
    Hello everyone.
    Excuse me, does anyone know how to remove a gui.box after pressing a key? My code is:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Keypad : MonoBehaviour
    5. {
    6.  
    7.     public string curPassword = "";
    8.     public Animator anim;
    9.     public string input;
    10.     public bool onTrigger;
    11.     public bool doorOpen;
    12.     public bool keypadScreen;
    13.     public Transform doorHinge;
    14.  
    15.  
    16.     void OnTriggerEnter(Collider other)
    17.     {
    18.         onTrigger = true;
    19.     }
    20.  
    21.     void OnTriggerExit(Collider other)
    22.     {
    23.         onTrigger = false;
    24.         keypadScreen = false;
    25.         input = "";
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.         if (input == curPassword)
    31.         {
    32.             anim.SetBool("SwitchFlipped", true);
    33.         }
    34.         else
    35.         {
    36.             anim.SetBool("SwitchFlipped", false);
    37.         }
    38.     }
    39.  
    40.  
    41.     void OnGUI()
    42.     {
    43.         if (!doorOpen)
    44.         {
    45.             if (onTrigger)
    46.             {
    47.  
    48.                 if (Input.GetKeyDown(KeyCode.E))
    49.                 {
    50.                     keypadScreen = true;
    51.                     onTrigger = false;
    52.                 }
    53.             }
    54.  
    55.  
    56.             if (keypadScreen)
    57.             {
    58.                 GUI.Box(new Rect(0, 0, 115, 210), "");
    59.                 GUI.Box(new Rect(5, 5, 105, 25), input);
    60.  
    61.                 if (GUI.Button(new Rect(5, 35, 33, 33), "1"))
    62.                 {
    63.                     input = input + "1";
    64.                 }
    65.  
    66.                 if (GUI.Button(new Rect(40, 35, 33, 33), "2"))
    67.                 {
    68.                     input = input + "2";
    69.                 }
    70.  
    71.                 if (GUI.Button(new Rect(75, 35, 33, 33), "3"))
    72.                 {
    73.                     input = input + "3";
    74.                 }
    75.  
    76.                 if (GUI.Button(new Rect(5, 70, 33, 33), "4"))
    77.                 {
    78.                     input = input + "4";
    79.                 }
    80.  
    81.                 if (GUI.Button(new Rect(40, 70, 33, 33), "5"))
    82.                 {
    83.                     input = input + "5";
    84.                 }
    85.  
    86.                 if (GUI.Button(new Rect(75, 70, 33, 33), "6"))
    87.                 {
    88.                     input = input + "6";
    89.                 }
    90.  
    91.                 if (GUI.Button(new Rect(5, 105, 33, 33), "7"))
    92.                 {
    93.                     input = input + "7";
    94.                 }
    95.  
    96.                 if (GUI.Button(new Rect(40, 105, 33, 33), "8"))
    97.                 {
    98.                     input = input + "8";
    99.                 }
    100.  
    101.                 if (GUI.Button(new Rect(75, 105, 33, 33), "9"))
    102.                 {
    103.                     input = input + "9";
    104.                 }
    105.  
    106.                 if (GUI.Button(new Rect(5, 140, 105, 33), "0"))
    107.                 {
    108.                     input = input + "0";
    109.                 }
    110.                 if (GUI.Button(new Rect(5, 175, 33, 33), "-"))
    111.                 {
    112.                     input = input + "-";
    113.                 }
    114.                 if (GUI.Button(new Rect(40, 175, 33, 33), "/"))
    115.                 {
    116.                     input = input + "/";
    117.                 }
    118.                 if (GUI.Button(new Rect(75, 175, 33, 33), "C"))
    119.                 {
    120.                     input = "";
    121.                 }
    122.  
    123.             }
    124.             if (keypadScreen)
    125.             {
    126.  
    127.                 if (Input.GetKeyDown(KeyCode.P))
    128.                 {
    129.                     keypadScreen = ;
    130.                     onTrigger = true;
    131.                     input = "";
    132.                 }
    133.             }
    134.  
    135.  
    136.         }
    137.     }
    138. }