- Home /
How do I make buttons that turn into a text field?
How do I make buttons that turn into a text field?
I want it so the user sees buttons on the screen and when clicked they turn into a text field that has several lines of text. With the option of closing the field which then reverts back to a button ready to be clicked again.
Please help this unity nub!
Answer by Berenger · Feb 05, 2012 at 10:48 PM
You need to use the same rect for both of them. And probably a similar style as well, so it doesn't look weird. Then Do something like that :
var useTextField : bool = false;
function OnGUI(){
if( !useTextField )
if( GUI.Button( rect, "Press button to write" ) ) useTextField = true;
else
GUI.TextField( rect, ...)
}
I left the closing the textfield to you, good luck !
Answer by syclamoth · Feb 05, 2012 at 10:50 PM
Well, you can have something like this-
bool isATextField;
string fieldText;
void OnGUI()
{
if(isATextField)
{
fieldText = GUILayout.TextField(fieldText);
isATextField = !GuiLayout.Button("Close");
} else {
isATextField = GuiLayout.Button("Be a Text Field!");
}
}
Your answer
Follow this Question
Related Questions
UI button not working 1 Answer
how to make multiple purchase buttons in just 2 scripts? 0 Answers
Moving buttons 1 Answer