- Home /
Question by
BrennanVargas1 · Jun 18, 2011 at 01:41 AM ·
c#windowsgui-button
Why dont my gui buttons work in a window?
I have my GUI Buttons set up in a window and everything but it still doesnt seem to work.
Heres the portion of the script
void OnGUI() {
XPandHealth();
if(GUI.Button(new Rect(10, 10, 100, 100), "Get XP!")){
XP += 50;
}
windowRect = GUI.Window(0, windowRect, PrimarySkill, "Primary Skill");
}
public void PrimarySkill(int windowID) {
GUI.DragWindow();
GUI.Label(new Rect(55, 20, 150, 150), " Points - " + Points.ToString());
if(isStrength == true) {
GUI.Label(StrengthLevelString, "Strength Level");
GUI.Label(StrengthDash, " - ");
if(PointAdd == true) {
if(GUI.Button(StrengthButton, "+")){
StrengthLevel += 1;
StrengthPoints += 3;
Points -= 1;
}
}
GUI.Label(StrengthLevelDisplay, StrengthLevel.ToString());
GUI.Label(StrengthPointsDisplay, "Strength Points - " + StrengthPoints.ToString());
}
if(isArchery == true){
GUI.Label(ArcheryLevelString, "Archery Level");
GUI.Label(ArcheryDash, " - ");
if(PointAdd == true) {
if(GUI.Button(ArcheryButton, "+")){
ArcheryLevel += 1;
ArcheryPoints += 3;
Points -= 1;
}
}
GUI.Label(ArcheryLevelDisplay, ArcheryLevel.ToString());
GUI.Label(ArcheryPointsDisplay, "Archery Points - " + ArcheryPoints.ToString());
}
if(isMagic == true) {
GUI.Label(MagicLevelString, "Magic Level");
GUI.Label(MagicDash, " - ");
if(PointAdd == true) {
if(GUI.Button(MagicButton, "+")){
MagicLevel += 1;
MagicPoints += 3;
Points -= 1;
}
}
GUI.Label(MagicLevelDisplay, MagicLevel.ToString());
GUI.Label(MagicPointsDisplay, "Magic Points - " + MagicPoints.ToString());
}
}
Comment
Best Answer
Answer by Bunny83 · Jun 18, 2011 at 02:47 AM
Because you execute DragWindow without parameter before your buttons. DragWindow without a rect will use the whole window. Since Unity's GUI is an immediate system the first thing you do will process all events before others have a chance.
So you can:
move DragWindow to the end of your PrimarySkill callback
provide a Rect that should be used as "drag area". Most of time you want only the title bar of the window be dragable. That's the example from the docs:
GUI.DragWindow (new Rect (0,0, 10000, 20));