Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Suggest a change


static function FocusControl(name: string): void;
static void FocusControl(string name);
static def FocusControl(name as string) as void


name Name set using SetNextControlName.


Move keyboard focus to a named control.

See Also: SetNextControlName, GetNameOfFocusedControl.

For focusing text in Editor GUI text fields, see EditorGUI.FocusTextInControl.

	// When pressed the button, selects the "username" Textfield.
	var username : String = "username";
	var pwd : String = "a pwd";
	function OnGUI () {
		// Set the internal name of the textfield
		GUI.SetNextControlName ("MyTextField");
		// Make the actual text field.
		username = GUI.TextField (Rect (10,10,100,20), username);
		pwd = GUI.TextField (Rect (10,40,100,20), pwd);

// If the user presses this button, keyboard focus will move. if (GUI.Button (Rect (10,70,80,20), "Move Focus")) GUI.FocusControl ("MyTextField"); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public string username = "username";
    public string pwd = "a pwd";
    void OnGUI() {
        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"))
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public username as string = 'username'

	public pwd as string = 'a pwd'

	def OnGUI() as void:
		username = GUI.TextField(Rect(10, 10, 100, 20), username)
		pwd = GUI.TextField(Rect(10, 40, 100, 20), pwd)
		if GUI.Button(Rect(10, 70, 80, 20), 'Move Focus'):

Your name (optional):
Your email (optional):
Please write your suggestion here: