- Home /
TextField does not show up
void OnGUI () {
GUILayout.BeginArea(new Rect(screenW / 4, 100, screenW / 2, screenH /
if(GUILayout.Button("Change the Server's IP")){
//set a user-defined ip address for client to connect
//the default ip is ethernet jack B48 in the CSL lab.
Log.Debug("reached");
MyClient.strIP = GUI.TextField(new Rect(screenW/2 - 150, screenH/2 - 75, 300, 150), MyClient.strIP, 15);
}
GUILayout.EndArea();
}
The textfield does not show up after click the button. but console does print "reached" which indicates the button click event is handled. So whats wrong with my code then?
Thank you in advance!
Answer by dorpeleg · Apr 18, 2013 at 07:58 PM
You need to add a bool value.
right now your code draws the text field for a millisecond when you press the button.
You need something like this:
if(GUILayout.Button("Change the Server's IP")){
ChangeServerIP = true
}
if(ChangeServerIP){
MyClient.strIP = GUI.TextField(new Rect(screenW/2 - 150, screenH/2 - 75, 300, 150), MyClient.strIP, 15);
}
should work.
i did as you said. but the new problem is the textfield does not disappear after i hit enter. i tried to set the bool back to false after initiate textfield, but this will prevent textfield from showing up again!
Why - are you taking the button away? Otherwise clicking it should make it show up again.
Change
ChangeServerIP = true
to
ChangeServerIP != ChangeServerIP
This is make it so it can turn the textfield on and off.
Answer by Dracorat · Apr 18, 2013 at 07:59 PM
You need to use GUILayout.TextField(MyClient.strIP)
- the GUI.TextField is for use without a GUILayout.
... And use the boolean as suggested above.
Your answer
![](https://koobas.hobune.stream/wayback/20220613100604im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with GUILayout and tooltip(C#) 1 Answer
Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer
How to fix ArgumentException? 3 Answers
How can I enable/disable a script or a method in a script from another editorwindow script ? 0 Answers
Display additional text before the variable that the user is editing in a GUI Text Field 1 Answer