- Home /
How do you add graphics and features to a GUI Window?
How do you add graphics to a GUI Window? For example: a background.
Also how do you add a 3D Text or label thing into a GUI Window?
EDIT: (ADDED CODE)
var endTime : float;
var textMesh : TextMesh;
var boolean = false; var windowRect = Rect(0,0,360,480);
function Start() { endTime = Time.time +60;
textMesh = GameObject.Find ("Timer").GetComponent(TextMesh);
textMesh.text = "60";
}
function Update () {
var timeLeft : int = endTime - Time.time;
if ( timeLeft < 0)
{
timeLeft = 0;
boolean = true;
}
textMesh.text = timeLeft.ToString();
}
function OnGUI() {
if(boolean) GUI.WIndow (0, windowRect,DoMyWindow, "My Window");
}
function DoMyWindow (windowID : int) {
if( GUI.Button(Rect(10,20,100,20),"HelloWorld"))
print ("Got a click");
}
Answer by Mike 3 · Jun 24, 2010 at 08:56 AM
When you call the window function, you need to pass a function to it as a parameter
That function gets called when the window draws
What you need to do is add your Label into that function, and it should just draw it, with the coordinates starting at 0,0 for the top left of the window
To draw a background, use GUI.DrawTexture in that function with the same size as the window and 0,0 for x and y
Edit:
To make your window only show when you trigger it, you can just use a bool to set whether to draw or not
//at the top of the script var yourBool = false;
//the code which is going to draw the window if (yourBool) GUI.Window(blah blah);
//in the trigger yourBool = true;
One more question: do you know any easier ways of doing a pop up window?
:D funny. Could you make your bool script more precise because I'm a bit confused. I've got my GUI window going and all but the bool part is confusing.