- Home /
Display additional text before the variable that the user is editing in a GUI Text Field
I have a GUI text field and I want to display additional text in it ie: First Name " + myVariable
Here is my script:
myVariable = GUI.TextField(new Rect(Screen.width/2-(300/2), 225, 300, 25), "First Name: "+myVariable, 30);
I am Using C#.
Here is what I am getting:
Any help would be appreciated. Thanks.
Answer by Jeff-Kesselman · Apr 29, 2014 at 02:05 AM
Your problem is that you are including "First Naame" in your field, so thats part of what gets returned and stored back in your variable. next time around, it doe sit again, adding "First name:" again, and so on.
What you need to do is to use a Horizontal group and a label for your label, not make it part of the text in the text area. Like this:
GUILayout.BeginHorizontal();
GUILayout.Label("First Name:");
myVariable = GuiLayout.TextField(myVariable);
GUILAyout.EndHorizontal();
If you want to position the whole thing somewhere then wrap it in GUILayout.BeginArea()/GUILayout.EndArea().
Alternately you could manually position both the label and the text field by pixel coordinates, but thats a needless hassle.
Your answer
Follow this Question
Related Questions
GUILayout.TextArea/TextField not working. 1 Answer
Distribute terrain in zones 3 Answers
How to use variable in MailMessage To? 1 Answer
String to Var 2 Answers
Inputfield set as Variable 1 Answer