GUI.FocusControl

Switch to Manual
public static void FocusControl (string name);

Parameters

name 使用 SetNextControlName 设置的名称。

Description

将键盘焦点移动到某个命名控件。

另请参阅:SetNextControlNameGetNameOfFocusedControl

有关在 Editor GUI 文本字段中聚焦文本的信息,请参阅 EditorGUI.FocusTextInControl

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public string username = "username"; public string pwd = "a pwd"; void OnGUI() { GUI.SetNextControlName("MyTextField"); username = GUI.TextField(new Rect(10, 10, 100, 20), username); pwd = GUI.TextField(new Rect(10, 40, 100, 20), pwd); if (GUI.Button(new Rect(10, 70, 80, 20), "Move Focus")) GUI.FocusControl("MyTextField"); } }