Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by mnm2317 · Jan 26, 2012 at 06:59 AM · c#textcolorfont

Text/font color

I just want to change my font/text color using c# in my script. It seems simple enough but I keep seeing MUCH more complicated code out there, and not much in the way of c#, mostly in Java.

Comment
Add comment · Show 3
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 FLASHDENMARK · Jan 26, 2012 at 07:36 AM 0
Share

If you got it in either language you can easily convert it to the language of your preference.

avatar image mnm2317 · Jan 26, 2012 at 08:10 AM 0
Share

"easily" must be subjective, as syntax is my weak point and I'm still learning C#. :\

avatar image luizgpa · Jan 26, 2012 at 03:00 PM 0
Share

What kind of text? GUIText, 3D Text or OnGUI stuff?

3 Replies

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

Answer by karl_ · Jan 26, 2012 at 03:14 PM

If you're using Unity's GUI, change the color property like so:

http://unity3d.com/support/documentation/ScriptReference/GUI-color.html

 void OnGUI()
 {
     GUI.color = Color.blue;
     GUILayout.Label("I'm Blue!");
 }

If you're talking about GUIText and 3DText, you'll need to modify the material tint:

http://unity3d.com/support/documentation/ScriptReference/GUIText-material.html

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 mnm2317 · Jan 26, 2012 at 08:09 PM 0
Share

the "GUI.color" was what I needed. $$anonymous$$new it'd be something simple :). Thank you!

avatar image pborg · Jun 02, 2012 at 05:06 AM 0
Share

Is there a simple way to change to a color not on that list? I want to change $$anonymous$$e to orange.

avatar image
0

Answer by vikingfabian-com · Aug 28, 2014 at 08:01 AM

To make GUI.color to work, the text must have a white style. Out color = GUI.color * Style color.

 GUI.color = Color.blue;
 GUILayout.Label("I'm Blue!", EditorStyles.whiteLabel);

 
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
0

Answer by corkr900 · Aug 22, 2016 at 05:08 AM

I just spent several days looking for a good solution to this, and changing GUI.color was too universal of a change to work for my application. Eventually, reading through the docs, I found this solution, which I believe may be what you're looking for:

Let's say you want to make a particular GUI.Label green (default is white). To do this, you'll have to pass a GUIStyle object into your call to GUI.Label. Some GUI elements have 3 different states (normal, Active, Focused). A label only has normal, but GUIStyle doesn't know that. So you can set the textColor component of the normal GUIStyleState of your GUIStyle to green (or whatever color you choose), and then pass that GUIStyle into you call to GUI.Label. Example:

 public static void ColoredLabel(Rect position, string text, Color textColor){
      GUIStyle style = new GUIStyle();
      style.normal.textColor = textColor;
      GUI.Label(position, text, style);
 }
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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How to change color of part of a text? 1 Answer

Time.deltaTime using Hindi numbers? 1 Answer

Rotated multi-coloured text 1 Answer

How to change color via script 2 Answers

Color.white not so much white... 3 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