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!

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.

You need to use GUILayout.TextField(MyClient.strIP) - the GUI.TextField is for use without a GUILayout.

… And use the boolean as suggested above.