• 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
8
Question by Rufalo · Mar 27, 2010 at 08:08 PM · gui

Change GUI Font size and Color?

How can I change the font and color of a GUI.Label? And other GUI objects?

I'm sorry if this has bean answered before, but all I found were questions about how to change the GameObject GUIText.

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

7 Replies

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

Answer by Michael La Voie · Mar 27, 2010 at 08:28 PM

You need to supply a GUIStyle along with your draw call.

GUI.Label can take a style as a third parameter.

private void OnGUI()
{
    GUIStyle myStyle = new GUIStyle();
    myStyle.font = myFont;
    GUI.Label(new Rect(10,10, 100, 30), "Hello World!", myStyle);
}

The Font must be created as a game asset and can be assigned to the script via the property inspector. It can contain a material that will specify color.

As for creating the initial Font, it is often best to find a good ttf font that you like, import that, then assign a material with the appropriate color. This site has a bunch of great references on fonts.

Comment
Add comment · Show 4 · 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 Christian Stewart · Mar 28, 2010 at 04:35 AM 0
Share

Thanks, this is helpful to know.

avatar image xpecttrum · Mar 27, 2014 at 02:44 PM 0
Share

Hi guys, this solutions seams to be pretty good.

I did everything you guys suggested, but it is not working.

1) I created the asset called myGuiSkin, then,

on the script: 2) public GUISkin guiSkin;

3) Then I dragged the asset to the field.

4) I put .TTF font in assets/font directory

5) I selected the desired font in the button,label and window "parts" of myGUISkin

6) didn't work, nothing changes - dont know why...

avatar image Ripster · Jun 03, 2014 at 11:46 PM 1
Share

A very important thing to note is that Resources.Load() will not load your font unless it is in a folder named "Resources"

avatar image isteffy · Sep 11, 2015 at 01:07 PM 0
Share

Your fonts link isnt found. Where do I load myFont as an actual font. Even if i have myFont.ttf in Assets > font I still get the error "Cannot find myFont in the current context"

avatar image
15

Answer by Eric5h5 · Mar 27, 2010 at 08:39 PM

If you just want to change the color, you can use GUI.contentColor. (There's also GUI.color and GUI.backgroundColor.) You can scale content without having to use new styles or import fonts at different sizes by changing GUI.matrix, but it won't be pixel-perfect in that case.

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 moghes · Mar 18, 2013 at 06:13 PM 0
Share

@Eric5h5 you have mentioned that we can scale content without importing fonts at different sizes.. As I have asked here , and no one suggested anything about GUI.matrix .. can you explain a bit how to do that?

avatar image
11

Answer by jinxi · Nov 29, 2012 at 02:44 PM

First created a folder in Assets called Resources (Assets/Resources). And there I created an Folder Fonts.

Than

 void OnGUI() {
     // Create style for a button
     GUIStyle myButtonStyle = new GUIStyle(GUI.skin.button);
     myButtonStyle.fontSize = 50;
         
     // Load and set Font
     Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
     myButtonStyle.font = myFont;
         
     // Set color for selected and unselected buttons
     myButtonStyle.normal.textColor = Color.red;
     myButtonStyle.hover.textColor = Color.red;
 
     ...
 
     // use style in button
     bool testButtonTwo = GUI.Button(new Rect(10,10,50,50), "test", myButtonStyle);
 
     ...
 }
 
     
Comment
Add comment · Show 4 · 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 drudiverse · Jun 19, 2014 at 06:28 PM 1
Share

Solution works very nicely...

     var Label2:GUIStyle = new GUIStyle(GUI.skin.GetStyle("label"));
     Label2.fontSize = 22;
     Label2.normal.textColor = Color.yellow ;
avatar image michaelto20 · Jun 20, 2015 at 08:35 PM 1
Share

Thank you drudiverse!! Your solution is much easier than what is listed above. I'd rather do your way than need to import files, etc. Also I've included my code since it's C# just for others who might need help converting it, even though its pretty straight forward. I'll save somebody the time.

 void OnGUI() {
         GUIStyle myStyle = new GUIStyle (GUI.skin.GetStyle("label"));
         myStyle.fontSize = 32;
         GUI.Label (new Rect (100, 300, Screen.width / 2, Screen.height / 2), "Congratualtions you are awake!!!",myStyle);
         
     }
avatar image mb-taqawifar · Oct 15, 2016 at 04:43 PM 0
Share

your code is so good Tank you :)

avatar image tenh_un · Jul 03, 2019 at 08:37 AM 0
Share

it doesn't work for me. please help

avatar image
2

Answer by BobBobson108 · Jun 09, 2012 at 09:34 PM

If you just want to change the font and color, you can do this:

 public Font font;
 public Color color;

 //-------------------------------

 void OnGUI () {
     
     GUI.skin.font = font;
     GUI.color = color;
     
     //----ZOOM IN BUTTON----///
     
     if (GUI.Button (new Rect (10,10,64,64), "+")) {
         
         ZoomIn();
     }
 }

Just make a public variable called 'font' and drag the one you want into the Inspector, and pick your color from the Inspector too. You can keep all of the existing layout stuff this way.

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 Jip1912 · Jun 29, 2016 at 05:00 PM 0
Share

Thanks, this is what I needed. I only wanted to change the font.

avatar image
1

Answer by FrojoS · Jan 23, 2015 at 01:39 PM

Seriously? There is no pure code solution for this problem?

For version control, I really would like to avoid anything that is not 'hard coded'.

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 ayushvora · Dec 12, 2016 at 06:33 AM 0
Share

Terrible, right? F$$anonymous$$L

  • 1
  • 2
  • ›

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 People are following this question.

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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Battle Info 1 Answer

How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers

Activating GUI 2 Answers


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