- Home /
How to change the size of a GUI text (in a script)?
I've got this section of my code here:
void OnGUI(){
GUI.Label(new Rect(20, 10, 50, 60),": " + collected + "/60");
}
and i want to change the size of the GUI Label. I've tried changing the numbers but nothing seems to work. Please Help
Answer by Gantar180 · Mar 30, 2013 at 10:45 AM
As far as I know, you can't change the size in code. However, you can adjust the size in the Inspector. You have to create a new style. Use this script:
//Creates the new style. Name it whatever you want.
public GUIStyle customGUI;
void OnGUI() {
//Draws the label. For the last argument, be sure to use the same name you used to create the style.
GUI.Label(new Rect(10,10,500,300),"Hello, World!",customGUI);
}
Once you have this added to a GameObject, look in the Inspector to adjust the settings. As for adjusting the label, the first two arguments of "Rect" is the x and y position of the text, and the next two are how large of an area the text is shown in.
Links:
http://docs.unity3d.com/Documentation/ScriptReference/GUIStyle.html http://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html
Your answer
Follow this Question
Related Questions
Possible to change GUI.Label fontsize without using GUIStyle? 1 Answer
How can I set the UI Text font size higher than 300px ? | Unity 5.4 2 Answers
[HELP] GUI not showing up as they should be in the C# script 0 Answers
Best way to properly scale text? 0 Answers
How change font size in Editor (not game)? My eyes are broken. 0 Answers