I need a way to have a UI Text already selected at the beginning of the scene, so that I can type into it through the keyboard as soon as the game starts. There is a way to do that?
CodePudding user response:
Use this at start event..
EventSystem.current.SetSelectedGameObject(inputField.gameObject);
CodePudding user response:
You can use the base class Selectable
to refer to your ui element to make this a bit more generic. This works for all UI Components that inherit Selectable, which includes InputField, Button, and others.
public UnityEngine.UI.Selectable uiElement;
void Start()
{
uiElement.Select();
}
You can also refer to the specific ui element, same method applies.
public UnityEngine.UI.InputField inputField;
void Start()
{
inputField.Select();
}