I am new to Unity and I am trying to show a popUp on click of a button; but the popup is not shown. Here’s the code that I have used:
function OnGUI()
{
GUI.skin = mySkin;
if(GUI.Button (Rect (10,10,50,50), "", "ShopBtn"))
{
Debug.Log("Clicked the button with an shakeBtnTexture");
GUI.Box (new Rect (0,20,200,300),"");
}
}
I have created a skin in unity Editor where I’ve specified the background texture for the Normal state of the box. If I use GUI.Box method out the block of button, it is display; but it is not display if it is inside the button block. Any help would be greatly appreciated.
Your syntax must be wrong that’s all, or else its correct logically.
if your syntax is correct as per norms, try this:
private var showBox : boolean = false;
function OnGUI()
{
GUI.skin = mySkin;
if(GUI.Button (Rect (10,10,50,50), "ShopBtn"))
{
showBox = true;
}
if(showBox)
{
Debug.Log("Clicked the button with an shakeBtnTexture");
GUI.Box (new Rect (0,20,200,300),"Box is Showing, I am Happy! :)");
}
}
The reason you weren’t seeing even if the syntax is correct, is because logically the box was showing itself, but it vanished during the next frame update, because the Button click event is present only for a single frame. so, you have to set a variable that the button has been clicked once.
Get it? Hope this helps.
mark the question if it is solved for you.