• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Grady · Jun 29, 2011 at 06:07 AM · guisizechangefontlabel

How to set the font size in GUI.Label

Hey guys,

I was just wondering, I have created a GUI Label, but I was wondering, how do you change the font size????

Here is my code:

 var font : Font;
 
 function OnGUI () {
 GUI.skin.label.font = font;
 GUI.Label (Rect (650, 650, 300, 50), "MY TEXT");
 }

Thanks

-Grady

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by SilverTabby · Jun 29, 2011 at 06:14 AM

Pass a GUIStyle into the function and set the font size inside the GUIStyle.

http://unity3d.com/support/documentation/ScriptReference/GUIStyle.html

so your new code would be

var style : GUIStyle;
function OnGUI()
{
    GUI.Label(Rect(650, 650, 300, 50), "HELLO WORLD", style);
}

The 3d platformer tutorial has a section on GUIStyles at page 58

http://unity3d.com/support/resources/tutorials/3d-platform-game

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Grady · Jun 29, 2011 at 06:21 AM 0
Share

thanks so much!!!!!!!

avatar image ahmadi9112 · Feb 19, 2015 at 07:03 PM 0
Share

hi SilverTabby thanks so much

avatar image graham_branch · Jun 05, 2015 at 09:47 PM 1
Share

As someone who is new, it would be really useful if you, or someone else, could mention how to accomplish this purely through code. I would prefer not to always specify these things from the editor.

avatar image Steven B · Jun 17, 2015 at 07:19 AM 4
Share

@graham_branch First you want to create a GUIStyle variable. Then you will want to change the fontSize of that variable. For C#, it might look something like this:

 private GUIStyle guiStyle = new GUIStyle(); //create a new variable
 
 private void OnGUI ()
     {
         guiStyle.fontSize = 20; //change the font size
         GUILayout.Label("Write your text here.", guiStyle);
     }
avatar image graham_branch · Jun 17, 2015 at 02:40 PM 0
Share

Thanks Steven, instantiating the style was what I was struggling to figure out, though I did figure it out eventually.

avatar image
0

Answer by johnnieZombie · Oct 24, 2012 at 07:49 PM

Does this not work for Android?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Deepscorn · May 19 at 10:45 PM 0
Share

You probably need to multiply with dpi as fontSize is in pixels

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing a GUILabel text SIZE 3 Answers

Changing the size of a GUI label 1 Answer

multi line label with different font? 1 Answer

Change Font Size of GUI Table 0 Answers

Change GUI Font Size Dynamically? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges