- Home /
text box and button won't display
hey guys, can you help me out please... i have the following code, which should to the best of my knowledge, display a button, and once it is clicked, a method call thing() [its a temporary name haha] should be called. My problem is this the print("HELLO") is run, but the text box and secondary button never appear for some reason. Any help would be greatly apretiated. the following is the code. var word: String;
function OnGUI(){
if (GUI.Button(Rect(20,20,100,20), "Import Image")){
thing();
}
}
function thing(){
print("HELLO");
word=GUI.TextField (Rect (20, 50, 200, 50), word);
if (GUI.Button(Rect(20, 80, 100,20), "SUBMIT")){
print(word);
}
return;
}
Answer by cj_coimbra · Dec 16, 2011 at 01:15 PM
That´s because they appear for a very short period once you click your other button that call thing() function. Put your textfield call outside that function and inside OnGUI() and it will display.
i know but i only want to see the text field after the button is clicked...if i do it inside the OnGUI() it will be always there
I see. Well, wrap it around a boolean like:
if (buttonWasClicked == true) { //your textfield code here }
And then you start this buttonWasClicked variable with false, when you click your first button, set it to true. That way, your textfield will be displayed only after clicking even if it´s outside the thing() function. Inside thing() it´s not gona happen.
Answer by delta25 · Dec 16, 2011 at 09:01 PM
i know but i only want to see the text field after the button has been clicked..
Your answer
Follow this Question
Related Questions
Making Text Boxes With Letters Appearing One At A Time 2 Answers
GUI buttons glow/flash/fade between textures 0 Answers
How do I make a custom font for a GUI button? C# 1 Answer
Tutorials for 2D game GUI 2 Answers
In Game Notepad 2 Answers