- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Magnomous · Jul 09, 2013 at 09:37 AM ·
gui.buttongui.box
GUI.Box inside of GUI.Button doesn't appear
Hi all, as first, sorry for my bad english.
Don't you know why GUI.Box inside of GUI.Button in my script does not appear? I wanted it worked like if you clicked on the GUI.Button, then GUI.Button will disappear and GUI.Box will appear. Here is the script:
static var TotalHP : int = 100;
static var TotalMB : int = 60;
static var TotalDamage : int = 10;
static var TotalDefence : int = 15;
function OnGUI() {
if(GUI.Button(Rect(Screen.width / 70, Screen.height / 1.15, 50, 50), "Stats")) {
GUI.Box(new Rect(Screen.width/35, Screen.height / 1.8, 300, 300), "HP: " + ManaAndHealth.curHP + " / " + TotalHP + "\n" +
"MB: " + ManaAndHealth.curMB + " / " + TotalMB + "\n" +
"Damage: " + TotalDamage + "\n" +
"Defence: " + TotalDefence + "\n");
}
}
Thank you for any response!
Comment
Best Answer
Answer by swyrazik · Jul 09, 2013 at 10:26 AM
You should do something like this:
static var TotalHP : int = 100;
static var TotalMB : int = 60;
static var TotalDamage : int = 10;
static var TotalDefence : int = 15;
static var showBox : boolean = false;
function OnGUI() {
if (!showBox){
if(GUI.Button(Rect(Screen.width / 70, Screen.height / 1.15, 50, 50), "Stats")) {
showBox = true;
}
}
else{
GUI.Box(new Rect(Screen.width/35, Screen.height / 1.8, 300, 300), "HP: " + ManaAndHealth.curHP + " / " + TotalHP + "\n" +
"MB: " + ManaAndHealth.curMB + " / " + TotalMB + "\n" +
"Damage: " + TotalDamage + "\n" +
"Defence: " + TotalDefence + "\n");
}
}
Answer by DavidDebnar · Jul 09, 2013 at 12:35 PM
Try using **GUI.RepeatButton** instead.
If you want a toggleable Box, use **GUI.Toggle**.
private var isBoxToggled : boolean = false;
function OnGUI () {
isBoxToggled = GUI.Toggle(Rect(0, 0, 50, 50), isBoxToggled, "Show Box!");
if(isBoxToggled) //GUI.Box code here
}