0
\$\begingroup\$

How do I close the GUI after the user enters a value? Is there any way to stop execution of the entire app (from inside this script) until a value is entered?

using UnityEngine;
using System.Collections;
using UnityEngine;
using UnityEditor;

public class Popup : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    string record="";

    void OnGUI() {
        //Participant Number/Record:
        GUILayout.Label ("enter participant id:");
        record = GUILayout.TextField(record);
        //GUILayout.TextField()

        if (GUILayout.Button("Submit")) {
            OnClickSavePrefab();
            GUIUtility.ExitGUI();
        }
    }

    void OnClickSavePrefab() {
        record = record.Trim();

        if (string.IsNullOrEmpty(record)) {
            EditorUtility.DisplayDialog("Unable to save record", "Please specify a valid participant record.", "Close");
            return;
        }
        // Save your prefab
        Debug.Log ("record:" + record);
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ We prefer to have only one question per question post. You could edit this question leave only one and ask another question with the second. \$\endgroup\$
    – Vaillancourt
    Commented Jan 21, 2016 at 22:19

1 Answer 1

1
\$\begingroup\$

Well, you can use simple flag to do so, as

using UnityEngine;
using System.Collections;
using UnityEngine;
using UnityEditor;

public class Popup : MonoBehaviour {

    bool _shouldDisplayGUI = true; // Make it false when you want to turn off GUI elements.

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    string record="";

    void OnGUI() {
        if (!_shouldDisplayGUI)
            return;

        //Participant Number/Record:
        GUILayout.Label ("enter participant id:");
        record = GUILayout.TextField(record);
        //GUILayout.TextField()

        if (GUILayout.Button("Submit")) {
            OnClickSavePrefab();
            GUIUtility.ExitGUI();
        }
    }

    void OnClickSavePrefab() {
        record = record.Trim();

        if (string.IsNullOrEmpty(record)) {
            EditorUtility.DisplayDialog("Unable to save record", "Please specify a valid participant record.", "Close");
            return;
        }
        // Save your prefab
        Debug.Log ("record:" + record);
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .