- Home /
[Solved]The Right way of doing PopUp
Holla ! i want to ask if what i do is aldy the right way of doing a popup? i've been looking about popup for a while and found out this was right, but, i have a problem where, the Gui.button couldn't click.. but GUI on the back of this one can clicked..
here is the image of what i mean. see that blue box behind is the GUI behind it, if i click it, the brown box popup ! but now if i want to press the red x button, i the button won't click.. but i can only click the button behind them.. is there any way to prevent this to happen? or does my way of popingup is wrong?
here's my code for the entire GUI, it's not much, so i will print all :)
#pragma strict
var buttonHealth : GUIStyle;
var buttonAttack : GUIStyle;
var buttonReward : GUIStyle;
var buttonTime : GUIStyle;
var popUp1: Texture;
var ispopUp : boolean;
var buttonOK : GUIStyle;
var buttonCancel : GUIStyle;
function Start () {
}
function OnGUI(){
if(GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.1,Screen.width*0.4,Screen.height*0.2)," ",buttonHealth)){
print("a");
ispopUp=true;
print("b");
}
GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.4,Screen.height*0.2)," ",buttonAttack);
GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.5,Screen.width*0.4,Screen.height*0.2)," ",buttonReward);
GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.7,Screen.width*0.4,Screen.height*0.2)," ",buttonTime);
if(ispopUp){
GUI.DrawTexture(Rect(Screen.width*0.3,Screen.height*0.3,Screen.width*0.5,Screen.height*0.5),popUp1);
GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.1,Screen.height*0.1)," ",buttonCancel);
}
}
Answer by xt-xylophone · Jan 20, 2014 at 02:31 AM
Your code for the button is not doing anything aside from drawing the button. Try:
if(GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.1,Screen.height*0.1)," ",buttonCancel)) {
ispopUp=false;
}
You never said that the cancel button actually did some cancel logic
@xt.xylophone yeah.. i added it, but that's not the problem, the problem is, i couldn't able to click it(touch) the red button there, but, the one that get clicked is the blue button behind the red one.. it's so irritating when i couldn't just set the layer of GUI, i mean maybe after it popup, i want so the back blue thing will not able to clicked.. is there any way to achieve this?
In the if statement for that blue button you could put
&& !ispopUp
This means the button will not work as long as ispopUp is true
Your answer
Follow this Question
Related Questions
help with errors 2 Answers
Setting Scroll View Width GUILayout 1 Answer
[Solved]GUI won't pop out 1 Answer
make key as a button 1 Answer
Move the text in a GUI Button/Box 1 Answer