- Home /
 
How do I remove this text box
I have made a script that hands input to a text box, but I want that text box to disappear when the enter or return keys are pressed. But how do I do that? I have spent all night trying to find a solution. Here is my script so far:
 #pragma strict
 
 var stringToEdit : String = "000";
 
 
 function OnGUI () {
     
      GUI.SetNextControlName ("WheelInput");
         // Make a text field that modifies stringToEdit.
         stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 3);
         
         GUI.FocusControl("WheelInput");
         
      
         if (Event.current.Equals (Event.KeyboardEvent ("[enter]")) || Event.current.Equals (Event.KeyboardEvent ("return"))) {
             
             //HOW DO I GET RID IF THIS TEXT BOX !!??      
       
         
     }
 
 }
 
               I will now probably just pass the information to another script and use Destroy (this) to remove the script and its text box. But I still would really like to know how to address and remove this text box.
Thanks for any help.
Answer by Shkarface-Noori · Aug 30, 2013 at 03:49 PM
a little change would make this work:
 #pragma strict  
 var stringToEdit : String = "000";
 private var showBox : boolean = true;
      
 function OnGUI () {    
          
         if (showBox == true)
         {
             GUI.SetNextControlName ("WheelInput");
             stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 3);
      
             GUI.FocusControl("WheelInput");
      
      
             if (Event.current.Equals (Event.KeyboardEvent ("[enter]")) || Event.current.Equals (Event.KeyboardEvent ("return"))) {
      
                 showBox = false; 
          }
      
         }
      
 
              Sorry for my bad scripting. The original script does not work properly. Here is one that works.
 #pragma strict
 
 
 var stringToEdit : String = "000";
 var showBox: boolean = true;
 
 function OnGUI () {
     
  
              
     
     if (showBox){
         
          GUI.SetNextControlName ("WheelInput");
            // $$anonymous$$ake a text field that modifies stringToEdit.
            stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 3);
         
            GUI.FocusControl("WheelInput");
         
                  
         if (Event.current.keyCode== $$anonymous$$eyCode.Return || Event.current.keyCode == $$anonymous$$eyCode.$$anonymous$$eypadEnter){
                        
             
             showBox = false;
             
                }
         
             }
 
     }
                 Your answer
 
             Follow this Question
Related Questions
Changing the text at the top of the window? 1 Answer
Dynamic width based on text width 1 Answer
How to make textbox? 2 Answers
Checking if a component has been removed or not at runtime 1 Answer
Unity & Visual Studio(removal) 0 Answers