I'm currently developing a Highscore system for Android. I have an Input field where the player will enter their name.
I want it so that the player doesn't have to tap on this input field in order to type into it. However, all my attempts have failed so far.
I currently have a prefab called HighScoreTemplate. This prefab has a UI Input Field (for the name) and UI Text object (for the score). It also has a script on it called HighScoreTemplate.cs.
I created a Select() function in the HighScoreTemplate.cs script that will call .Select() on the input field and then .ActivateInputField() afterwards.
public void Select()
{
// Select it
NameField.Select();
NameField.ActivateInputField();
}
However, this wasn't automatically selecting the NameField input field, as the keyboard did not pop up on my Android device.
I have verified through debugging that this Select() function is being called and run.
I have also verified that this input field is interactable, I can see the checkbox for it checked in the inspector when I select it.
I then assumed that maybe Unity had a delay, so I attempted this test to see if it would work:
int counter = 1;
while(counter <= 50 && !_newHighScoreTemplate.NameField.isFocused)
{
_newHighScoreTemplate.Select();
Debug.Log("Select Attempt #" + counter);
counter++;
}
This test gave me the same result, the android keyboard did not pop up and allow me to input text into the input field.
Can someone please shed some light on what I'm doing wrong? Why is my input field not gaining focus and why is the keyboard in Android not popping up so that I can type into the field without having to tap onto it first?