2018-04-27 UGUI InputField获取输入焦

2018-04-27  本文已影响0人  Nmao

UGUI中的InputField控件如何自动获取输入焦点:

方法1:InputField.ActivateInputField

usingUnityEngine;

usingSystem.Collections;usingUnityEngine.UI;

publicclassExample : MonoBehaviour 

{

publicInputField mainInputField;

// Activate the main input field when the scene starts.

void Start ()    {        mainInputField.ActivateInputField();  

  }}

方法2 EventSystem.SetSelectedGameObject

usingUnityEngine;

usingSystem.Collections;

usingUnityEngine.UI;

publicclassExample : MonoBehaviour

 {

public  InputField   mainInputField;// Activate the main input field when the scene starts.

void    Start ()    {        EventSystem.current.SetSelectedGameObject(mainInputField.gameObject);    }}

上一篇下一篇

猜你喜欢

热点阅读