- Home /
[Solved]GUI won't pop out
so basically i want to pop up some gui.. and here's my code..
var button1 : GUIStyle;
var button2 : GUIStyle;
var popUp1: Texture;
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)," ",button1)){
print("a");
GUI.DrawTexture(Rect(Screen.width*0.4,Screen.height*0.4,Screen.width*0.5,Screen.height*0.5),popUp1);
print("b");
}
GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.4,Screen.height*0.2)," ",button2);
}
in the console it printed "a" and "b" but, the the game doesn't Draw the "popUp1" Texture. does my code is wrong or something? thanks for further help :)
Answer by goo-muffin · Jan 18, 2014 at 08:12 PM
It draws the texture... but only for one frame. What you have to do is to switch any value (in most cases a boolean) so that unity "knows": From now on in all the frames you should draw the Texture. Do something like:
var button1 : GUIStyle;
var button2 : GUIStyle;
var popUp1: Texture;
var ispopingUp :boolean;
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)," ",button1)){
print("a");
ispopingUp = true;
print("b");
}
GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.4,Screen.height*0.2)," ",button2);
if(ispopingUp)
{
GUI.DrawTexture(Rect(Screen.width*0.4,Screen.height*0.4,Screen.width*0.5,Screen.height*0.5),popUp1);
}
}
(Sorry for bad formatting ;) )
yeph, formatting is not half bad ;) btw, thanks for good explanation.. now i kind of understand why :D
Your answer
Follow this Question
Related Questions
[Solved]The Right way of doing PopUp 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Limit on GUI Components? 0 Answers
Setting GUI color alpha math issue. 2 Answers