- Home /
Question by
SuprisePartyFiddlesticks · Apr 07, 2015 at 01:35 AM ·
unity 5javascriptgui-button
GUI problems... Cant be specific in title
So, what i'm trying to do is to display a new button, when an other button is displayed. And then when the new button is clicked it should dissappear. But it won't even appear at all now. Clicking the button won't display it. All the other buttons works fine though.
CODE : #pragma strict
//Variable Initialization
var img_infoBtn : Texture;
var img_clickerBtn : Texture;
var closeClickerInfo = true;
var coins : int = 100;
function OnGUI()
{
if (GUI.Button(Rect(30, Screen.height / 2, 200, 50), img_clickerBtn))
{
Debug.Log("TEST");
}
if (GUI.Button(Rect(235, Screen.height / 2, 50, 50), img_infoBtn))
{
closeClickerInfo = false;
if (GUI.Button(Rect(240, Screen.height / 2, 50, 500), "Gives you +1 coin per second. Click me to close") && closeClickerInfo == false)
{
closeClickerInfo = true;
}
}
}
Comment
Answer by OrbitSoft · Apr 07, 2015 at 07:10 AM
In this code the third button only appears one frame, only when you click the second button.
The right way to do what you want should be:
// second button
if (GUI.Button(Rect(/*pos*/), img_infoBtn))
{
closeClickerInfo = false;
}
if (!closeClickerInfo)
{
if (GUI.Button(Rect(/*pos*/),"Text"))
{
closeClickerInfo = true;
}
}
Answer by Vetle · Apr 07, 2015 at 09:52 AM
You have to put the button you want to show out of the if statement.