protected void OnFocus ();

설명

Focus the input field initializing properties.

Handles what happens after a user selects an InputField. This is a protected property. To return the focus state use InputField.isFocused. To shift focus to another GameObject, use EventSystem.SetSelectedGameObject.

A common use of this is allowing the user to type once focussed. Another way is outputting a message when the user clicks on a field (often seen when creating passwords).

//Create an Input Field by going to Create>UI>Input Field. Attach this script to the Input Field GameObject

using UnityEngine; using UnityEngine.UI;

public class Example : MonoBehaviour { InputField m_InputField; void Start() { //Fetch the Input Field component from the GameObject m_InputField = GetComponent<InputField>(); }

void Update() { //Check if the Input Field is in focus and able to alter if (m_InputField.isFocused) { //Change the Color of the Input Field's Image to green m_InputField.GetComponent<Image>().color = Color.green; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961