Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
6
Question by Ranza · May 19, 2010 at 08:50 PM · colorfontguistyle

Custom font in GUI.Label, but can't change it's color

Hi, I followed the Michael La Voie answer from this post: http://answers.unity3d.com/questions/6585/change-gui-font-size-and-color , but I can't change font color. By default the shader of an imported font is read-only and I can't manually change the color, though here are 2 script attempts which failed:

  • GUI.color = Color.red;
  • myStyle.font.material.color = Color.red;

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

6 Replies

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

Answer by Edy · May 31, 2010 at 02:44 PM

I came to the same problem and found a simple solution. This is JavaScript but sure you get the point if you want to use C#:

var TextStyle = new GUIStyle();

function OnGUI () {
GUI.Label (Rect (10, 10, 200, 80), "This is a styled text", TextStyle); }

Add the above script to any GameObject. The script component will now publish a property TextStyle, where you can edit and control all of its properties at design time:

  • TextStyle -> Normal -> Text Color for setting the text color.
  • TextStyle -> Font for specifying any font (drag & drop from your Assets or choose from the drop-down menu).

Of course, you can also set the properties at runtime:

function OnStart ()
{
    TextStyle.normal.textColor = Color.red;
    TextStyle.font = myFont;
}
Comment
Add comment · Show 2 · 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 monotoan · Mar 09, 2017 at 04:40 PM 2
Share

To clarify, since this is an old answer:

If you're working with a GUIStyle (so you can set fontsize, etc.), the line of code you need to change the color is:

myGUIStyle.normal.textColor = Color.red; // ( or Color.white or Color.whateverYouWant )

Setting colors on the GUI object (e.g. GUI.contentColor), as suggested by most of the other answers, WON'T work if your text is being displayed with a GUIStyle.

avatar image liam4567890 monotoan · Aug 05, 2021 at 12:03 AM 0
Share

Thank you very much mono, this saved me a lot of googling.

avatar image
2

Answer by Molix · May 20, 2010 at 01:08 AM

I think you want GUI.contentColor, e.g.

GUI.contentColor = Color.red;
Comment
Add comment · Show 2 · 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 Ranza · May 23, 2010 at 05:56 PM 0
Share

doesn't work either...

avatar image Molix · May 23, 2010 at 08:21 PM 1
Share

In a clean project with default styles that works, so the issue must be something else. To be clear, you set the GUI.color or GUI.contentColor right before drawing the text with GUI/GUILayout. The color is multiplied into your text color, so if your GUIStyle uses a black color, it will stay black -- make sure the style is using white.

avatar image
2

Answer by Litobyte_Softworks · Sep 14, 2011 at 06:47 PM

Try this in your start function:

TextStyle.normal.textColor = Color.red;

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
avatar image
-1

Answer by Jeejo · Apr 28, 2013 at 02:11 AM

This should work:

 var TextColor : Color = Color.white;
 
 function Start () {
     guiText.material.color = TextColor; 
 }
 
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 Eric5h5 · Apr 28, 2013 at 03:11 AM 0
Share

The question is about OnGUI code, not GUIText objects.

avatar image
0

Answer by Veehmot · Apr 28, 2013 at 12:45 AM

As of Unity 4, this works:

 GUI.color = Color.red
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
  • 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.

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

How do I change my font in code? 1 Answer

How do I change the font and color of GUI text? 0 Answers

Script loads font, how do I change the color? 2 Answers

How do I change the font and color of GUI text? 1 Answer

Help with GUIstyles between platforms 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