- Home /
Question by
kohenb · Jul 27, 2011 at 02:41 PM ·
onmousedowngui.boxconditional
How to make a GUI button appear OnMouseDown
Hi, I am working on some code, that when an object appears a GUI box appears with some text. However the issue is that, as soon as I run my game it appears and is not being triggered by my if statement. I only want it to appear, when the particular object gets clicked.
private var InfoBox = false;
var boxwidth: int = 300;
var boxheight: int = 300;
var boxfromleft: int = 500;
var boxfromtop: int = 500;
function OnMouseDown () {
if (Input.GetMouseButtonDown)
InfoBox = true;
}
}
function OnMouseExit () {
InfoBox = false;
}
function OnGUI () {
if (InfoBox) {
GUI.BeginGroup (Rect(boxfromleft,boxfromtop,boxwidth,boxheight));
GUI.Box(Rect(0,0,200,200),"A Classic Neo-Victorian Turret");
GUI.Button(Rect(10,40,150,40),"Browse All Turrets");
GUI.EndGroup ();
}
}
Thanks for the help in advance Kohen.
Comment
Actually, I got it to work! ins$$anonymous$$d of using BeginGroup and EndGroup actions,
I used the GUILayout.BeginArea and EndArea, calls. With a TextArea and Button, in between!
$$anonymous$$
Your answer
![](https://koobas.hobune.stream/wayback/20220612160352im_/https://answers.unity.com/themes/thub/images/avi.jpg)