Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Not Works GUI.FocusControl

Discussion in 'Immediate Mode GUI (IMGUI)' started by BIV1991, Jan 26, 2015.

  1. BIV1991

    BIV1991

    Joined:
    Jan 26, 2015
    Posts:
    7
    using UnityEngine;
    using System.Collections;

    public class NewBehaviourScript : MonoBehaviour
    {
    static string killFocusName = "killFocus";
    static string text = "TEXT";
    void OnGUI()
    {
    GUI.SetNextControlName(killFocusName);
    GUILayout.Label("TEXT");

    GUI.changed = false;
    text = GUILayout.TextField(text, GUILayout.MinWidth(40));
    if (GUI.changed)
    {
    GUI.FocusControl(killFocusName);
    Debug.Log("focus killed ????, NO!!!!!!!!!!!!!!");
    }
    }
    }
     
  2. Immanuel-Scholz

    Immanuel-Scholz

    Joined:
    Jun 8, 2013
    Posts:
    221
    SetNextControlName sets the name of the NEXT control. You are putting it before a label, which cannot receive your focus.

    Try moving SetNextControlName down just before the GUILayout.TextField line.