I had a similar problem. I had 5 input fields and I wanted to be able to move smoothly from one to the other without having to use the mouse to select the next field. I tried the OnSubmit
and OnEndEdit
functions but could not trap the message. However, the OnValueChanged
worked perfectly.
I decided that I would sacrifice the tab key and examined the last key pressed.
public int InputFocus = 0;
//Point the OnValueChanged of each InputField to the following function
public void TextEdited()
{
bool tabPressed = Input.GetKeyDown(KeyCode.Tab); //Check required keypress
if (tabPressed)
ChangeInputFocus();
}
public void ChangeInputFocus()
{
InputFocus = (InputFocus + 1) % 5;
switch (InputFocus)
{
case 0:
InputField2.Select();
break;
case 1:
InputField3.Select();
break;
case 2:
InputField4.Select();
break;
case 3:
InputField5.Select();
break;
case 4:
InputField1.Select();
break;
}
}
It is a simple solution - but it worked for my application. I guess it would also work in other cases too.
Can't I do it with the new Unity 4.6 UI system?
– Solley