• 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 · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

multi line label with different font? 1 Answer

Changing a GUILabel text SIZE 3 Answers

Changing the size of a GUI label 1 Answer

Why does my non-dynamic label text not resize in Android? 2 Answers

Is there a way to get the size of text? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges