- Home /
Making the words print in the middle of the Gui.TextField?
Hi! I'm working with a GuiTextField and the words are print from the left side of GuiTextField
But I want to know how can I print in the middle of the GuiTextField. Can somone help me please?
this is the code I have written:
GUI.TextField(new Rect(TextFieldScreenWidth,TextFieldScreenHeight,TextFieldWidth, TextFieldHeight), "4359465779899875454", 25);
Thanks for help !
Answer by Bunny83 · Jun 16, 2011 at 12:39 PM
If you don't want to create a custom skin you can copy the TextField style and modify it as you need. GUIStyle.alignment is what you need to set to TextAnchor.MiddleCenter.
//C#
GUIStyle myStyle = new GUIStyle(GUI.skin.textField);
myStyle.alignment = TextAnchor.MiddleCenter;
GUI.TextField(new Rect(TextFieldScreenWidth,TextFieldScreenHeight,TextFieldWidth, TextFieldHeight), "4359465779899875454", 25, myStyle);
By the way: It seems you use a TextField just to display a text. A TextField is meant as input field where the user can input text. To only display text you should use a Label. You still can use the TextField style so it looks like a TextField but it's a label.
That works with all styles.
Thanks for your help! It works perfact! And I also try to use GUI.Label it works good too.