- Home /
How to make GUI Labels and Buttons show in a GUI Window
How can i take this void which is also stated in the OnGUI function and make all these labels shown in a Window or DragWindow. Im not a professional when it comes to GUI's so i dont really know how to do this but the GUI's Show up and ive attempted to get them to show up in a Window before but i had to luck. I eventually want to be able to push "I" and have this window pop up with these in it.
Heres the public void
public void PrimarySkill() {
GUI.Label(new Rect(45, 10, 150, 150), "Points - " + Points.ToString());
GUI.Label(new Rect(10, 30, 150, 150), "Strength Level -");
if(GUI.Button(new Rect(115, 30, 35, 15), "+")){
StrengthLevel += 1;
Points -= 1;
}
GUI.Label(new Rect(180, 30, 150, 150), StrengthLevel.ToString());
GUI.Label(new Rect(10, 60, 150, 150), "Archery Level -");
if(GUI.Button(new Rect(115, 60, 35, 15), "+")){
ArcheryLevel += 1;
Points -= 1;
}
GUI.Label(new Rect(180, 60, 150, 150), ArcheryLevel.ToString());
GUI.Label(new Rect(10, 90, 150, 150), "Magic Level -");
if(GUI.Button(new Rect(115, 90, 35, 15), "+")){
MagicLevel += 1;
Points -= 1;
}
GUI.Label(new Rect(180, 90, 150, 150), MagicLevel.ToString());
}
Answer by DaveA · Jun 17, 2011 at 02:28 AM
See http://unity3d.com/support/documentation/ScriptReference/GUI.Window.html but I usually use http://unity3d.com/support/documentation/ScriptReference/GUILayout.Window.html. To make it draggable use http://unity3d.com/support/documentation/ScriptReference/GUI.DragWindow.html
so it might look something like this:
function OnGUI () {
// Register the window.
windowRect = GUI.Window (0, windowRect, PrimarySkill, "Primary Skill");
}
Be sure to add windowID : int as params to PrimarySkill
Thanks, it worked great, i can drag it and everything. Now i just need to be able to press "I" to get it to open. Have any idea on how to do that.
function Update ()
{
if ( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.I) ) {
Debug.Log("The I key has been pressed");
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Why dont my gui buttons work in a window? 1 Answer
Making a GUI button appear after pressing another GUI button? C# 1 Answer
Enable and disable a button selection 3 Answers