- Home /
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?
Answer by Waz · Apr 26, 2010 at 11:10 AM
This works for me:
- Add a font (eg. a TTF from http://1001freefonts.com) to your project Assets.
- Expand it's children in the view - you'll see a "font texture" and a "font material" under each typeface in the font.
- Set the size of the font in the "font texture" (duplicate all this to get more sizes, or scale when using).
- Right click on the "font material" of a font, select "Create -> Material" (or select it and choose Material fron the Create menu).
- You should get a new "font material" added. I recommend renaming it too " - ".
- Select the new "font material", and set its Font Texture to the texture of the font you created it from.
- Now finally, set the color on this "font material".
- 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
- helv
- Helvetica
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.
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.
I am trying to do the same. But the font $$anonymous$$aterial part is disabled for almost all the font that i have tried importing which include museosans,segoe,teen,veteran_typewritter,digital,verdana.. what can be the reason for this
Answer by Eric5h5 · Mar 02, 2010 at 09:21 PM
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.
Answer by rocket5tim · Mar 03, 2010 at 01:27 AM
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.
Answer by headkit · May 04, 2010 at 07:56 AM
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);
Using Arrays like that is a strange idea...just set the values directly ins$$anonymous$$d, 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.
Answer by Rich · Nov 05, 2010 at 07:57 PM
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.