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?

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.

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.

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.

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);

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.

//Just put the alpha to 1

var miColor : Color;

function Start()

{

    renderer.material.color = miColor;

    //Para que se vea el texto

    renderer.material.color.a = 1;

}