x


Change color of 3D text or font

The 3D text and font systems in unity seems quite broken. How do I change the color of a font or 3D text?

more ▼

asked Mar 02 '10 at 04:50 PM

Johan gravatar image

Johan
21 1 3 3

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

This works for me:

  1. Add a font (eg. a TTF from http://1001freefonts.com) to your project Assets.
  2. Expand it's children in the view - you'll see a "font texture" and a "font material" under each typeface in the font.
  3. Set the size of the font in the "font texture" (duplicate all this to get more sizes, or scale when using).
  4. Right click on the "font material" of a font, select "Create -> Material" (or select it and choose Material fron the Create menu).
  5. You should get a new "font material" added. I recommend renaming it too " - ".
  6. Select the new "font material", and set its Font Texture to the texture of the font you created it from.
  7. Now finally, set the color on this "font material".
  8. Repeat steps 4-7 for each color.

You should see something like this in your Project panel:

  • Fonts
    • Helvetica
      • helv
        • font Texture
        • font material
      • helv - green

With the above set up, whenever you create a 3D text, you must select the font in the Project, then Create the 3D text, then select the other font material in the new 3D text. If you don't pick them right, you just get junk text or text that is not at the right position in space.

This may seem "broken", but you need to understand how fonts work in games: they are bitmaps rendered with a shader, not TTF outline path drawings. Unity allows you to just drop in a TTF and it makes the bitmaps for you, but it's not a DTP program ;-).

Next, you'll want to know how to make it go behind other objects.

more ▼

answered Apr 26 '10 at 11:10 AM

Waz gravatar image

Waz
6.5k 22 33 71

@warwick you saved my day. thanks :)

Feb 20 '12 at 07:24 AM jason0202

You left out one step. You have to make sure to set the Shader of the new material to GUI/Text Shader. Put that at like step 6.5. You should see the preview change from a solid color to text wrapper around a sphere.

3 days ago serff
(comments are locked)
10|3000 characters needed characters left

Neither 3D text nor regular text are "broken". For 3D text you change the color the same way as any other object, by using renderer.material.color. If you're using text in an OnGUI function, change GUI.color.

more ▼

answered Mar 02 '10 at 09:21 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(comments are locked)
10|3000 characters needed characters left

Find your font in your project folder (inside unity), then click the little "down arrow" next to the font name. Under the font you'll see a "font material" and a "font Texture". Select the font material and in the inspector there's a Text Color field with a white rectangle next to it. Click the white rectangle and choose a new color from the color picker.

All of this assumes that you've added a TTF font to your project. I don't think it's possible to change the color of the default font (Arial Rounded Bold) since it's not exposed in the project.

more ▼

answered Mar 03 '10 at 01:27 AM

rocket5tim gravatar image

rocket5tim
859 12 17 33

(comments are locked)
10|3000 characters needed characters left

try something like

var theColor = new Array(0, 0, 1);
var clr = Color(theColor[0], theColor[1], theColor[2], 1);

// if your gameObject has a Child you want to change color
gameObject.transform.Find("Your Child to Change Color").gameObject.renderer.material.SetColor ("_Color", clr);
// or directly
// gameObject.renderer.material.SetColor ("_Color", clr);
more ▼

answered May 04 '10 at 07:56 AM

headkit gravatar image

headkit
280 25 28 36

Using Arrays like that is a strange idea...just set the values directly instead, it's much faster and easier. Also you can just use renderer.material.color = myColor, no need to use SetColor for that, and you can leave out gameObject in that case too.

May 04 '10 at 09:16 AM Eric5h5

you're right, man.

May 05 '10 at 07:32 AM headkit
(comments are locked)
10|3000 characters needed characters left

I read Warwick's answer, and the thing that made it work for me, in Unity 3, is to be sure to set the Shader to be "GUI/Text Shader" rather than the default "Diffuse" when I replaced the Font material with my new, colored font material.

more ▼

answered Nov 05 '10 at 07:57 PM

Rich gravatar image

Rich
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x510
x241
x103

asked: Mar 02 '10 at 04:50 PM

Seen: 26806 times

Last Updated: 3 days ago