- Home /
How come GUI window are not close according
var isWrong = false;
function Update()
{
.
.
.
else if(selected_00.GetComponent(textOnMouse00).thisRadical.ID != selected_0.GetComponent(textOnMouse0).thisRadical.ID)
{
isWrong = true;
//score -= 500;
}
}
}
function OnGUI()
{
if(isWrong)
{
GUI.Window(0, Rect((Screen.width/2)-90, (Screen.height/2)-190, 300, 150), showGUI, "I'm Sorry!!");
}
}
function showGUI()
{
if(isWrong)
{
// You may put a label to show a message to the player
GUI.Label(Rect(65, 50, 200, 80), "Boo..Boo.. WRONG WORDS!!!");
}
// You may put a button to close the pop up too
if (GUI.Button(Rect(60, 90, 75, 30), "OK"))
{
isWrong = false;
}
}
I would like to ask what wrong with my code. It can't seem to close the window if i click ok.
Answer by CHPedersen · Jul 22, 2011 at 07:13 AM
It's possible that the conditional that sets isWrong = true continually evaluates to true, i.e. selected_00.GetComponent(textOnMouse00).thisRadical.ID
is never equal to selected_0.GetComponent(textOnMouse0).thisRadical.ID
, so even if the Window's Ok-button sets isWrong = false, it gets set right back to true next time Update executes. If I were you, I'd insert a call to Debug.Log inside that if-statement and see if it gets printed to the console continually.
You make sure isWrong doesn't get continually set to true. ;) That is, of course, a bleeding obvious comment and not very useful to you, but that's because I don't know what lies behind selected_00.GetComponent(textOn$$anonymous$$ouse00).thisRadical.ID, what that ID is, when it gets set, whether one of them returns null, or something like that. You need to study that and figure that out for yourself.
Your answer
![](https://koobas.hobune.stream/wayback/20220612152850im_/https://answers.unity.com/themes/thub/images/avi.jpg)