- Home /
How to focus on TextField2 when TextField1 is compeleted
Hi I have four TextField for getting a serial number. When the scene is loaded TextField1 must be focused automatically and when TextField1 was completed with four digit, TextField2 must be focus automatically and similarly.
How can I do it?
         GUI.SetNextControlName("text1");
         stringToEdit1 = GUI.TextField (Rect (100, 100, 120f, 50f), stringToEdit1, 4 , myStyle1);
         GUI.FocusControl("text1");
         
         stringToEdit2 = GUI.TextField (Rect (300, 100, 120f, 50f), stringToEdit2, 4 , myStyle1);
         
         stringToEdit3 = GUI.TextField (Rect (500, 100, 120f, 50f), stringToEdit3, 4 , myStyle1);
         
         
         stringToEdit4 = GUI.TextField (Rect (700, 100, 120f, 50f), stringToEdit4, 4 , myStyle1);
Answer by ExtremePowers · Nov 04, 2014 at 04:47 PM
Wouldn't it be something like this:
          if (GUI.GetNameOfFocusedControl() == "text1") {
                   if (stringToEdit1.Length == 4) {
                            stringToEdit1 = "";
                   }
          }
          GUI.SetNextControlName("text1");
          stringToEdit1 = GUI.TextField (Rect (100, 100, 120f, 50f), stringToEdit1, 4 , myStyle1);
          GUI.FocusControl("text1");
          
          GUI.SetNextControlName("text2");
          stringToEdit2 = GUI.TextField (Rect (300, 100, 120f, 50f), stringToEdit2, 4 , myStyle1);
 
          //Add more here
 
          if (stringToEdit1.Length == 4) {
              GUI.FocusControl("text2")
          }
 
It doesn't work. TextField2 isn't focused automatically after that TextField1 is completed.
Your answer
 
 
             Follow this Question
Related Questions
GUI.FocusControl & GUI.SetNextControlName doesn't work 2 Answers
Can't Input when focus a text field 2 Answers
Using GUI.FocusControl on TextField selects all text 4 Answers
TextField, Event.current, Input.GetKey, and GUI.FocusControl locking 1 Answer
Disable feature that causes pressing "Tab" to cycle through available TextFields 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                