How can I make it, is that a GUI window closes itself after some time again. In other words, How can hide a GUI window after a certain time?
Thanks
How can I make it, is that a GUI window closes itself after some time again. In other words, How can hide a GUI window after a certain time?
Thanks
Have a boolean member variable that controls whether the GUI-window is rendered or not, and switch this variable to false in a CoRoutine. In C#, this could look like:
public class MyScript : MonoBehaviour {
public float showTimeSeconds = 5.0F;
private bool render = false;
private Rect windowRect = new Rect (20, 20, 120, 50);
public void ShowWindow() {
render = true;
StartCoroutine(HideWindow());
}
public IEnumerator HideWindow() {
yield return new WaitForSeconds(showTimeSeconds);
render = false;
}
public void OnGUI() {
if (GUI.Button (new Rect (10,20,100,20), "Show Window"))
ShowWindow();
if (render) {
windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
}
}
public void DoMyWindow(int windowID) {
if (GUI.Button (new Rect (10,20,100,20), "Hello World"))
print ("Got a click");
}
}
See also GUI Scripting Guide for an understanding of how immediate mode GUIs work.
No Funktion! nothing see on display