Changing font colour

I have 3 imported fonts in my project, the 'Text Color' button & color picker are ghosted, and do not work.

Is this a bug? I have attempted to re-import the fonts, but the option is still ghosted. I have also imported other fonts. Any ideas?

alt text

Ghosted!?

Well it may help to check if another computer / version etc. has the same problem with this font. That will get you the answer of WHERE the problem is pretty quickly. Usually it's not Unity3D being the problem. My rule of thumb is to never blame the computer because you just end up being wrong all the time :)

–

6 Answers

6

Definitely, not intuitive:

http://unity3d.com/support/documentation/Components/class-Font.html

Changing Font Color

There are different ways to change the color of your displayed font, depending on how the font is used.

GUIText & Text Mesh If you are using a GUIText or a Text Mesh, you can change its color by using a custom Material for the font. In the Project View, click on Create->Material, and select and set up the newly created Material in the Inspector. Make sure you assign the texture from the font asset to the material. If you use the built-in GUI/Text Shader shader for the font material, you can choose the color in the Text Color property of the material.

UnityGUI If you are using UnityGUI scripting to display your font, you have much more control over the font's color under different circumstances. To change the font's color, you create a GUISkin from Assets->Create->GUI Skin, and define the color for the specific control state, e.g. Label->Normal->Text Color. For more details, please read the GUI Skin page.

Okay so this is quite a step backward in terms of practicality since Unity iPhone 1.7 :) But if it works, it'll do.

–

Is this still valid? How do you associate the new Material to the font?

–

As zoon pointed out, you need to create your own custom font material and use that.

The reason is that we don't allow editing of imported assets, only of the import settings - otherwise, this would be a sure way of breaking things when using external version control. However, having an option for font color in the font importer seems like a very reasonable request, though.

Just add a script that does it here is one that makes it red…just change teal to any color you want

function Update () {

renderer.material.color = Color.red;

}

Simple :wink:

I thought this only worked with dynamic fonts (not available on mobile platforms)?

–

yeh don't change the renderer. Instead just access the material. var TextToChange : GUIText ; // Drag GUIText here function Start () { TextToChange.material.Color = Color.yellow; }

–

This will do :slight_smile:

var tex : Transform;

function Start() {

tex.guiText.text = "Hello";
tex.guiText.material.color = Color.green;

}

Try this code, it’ll allow you to change text mesh color interactively during edit time, and (just to be picky) it won’t change anything during play:

using UnityEngine;

[ExecuteInEditMode]
public class SetTextMeshColor : MonoBehaviour {

	public Color TextColor = Color.black;
	private Material _material ;

	void OnEnable () {
		_material = GetComponent<MeshRenderer>().sharedMaterials[0];
		_material.color = TextColor;
	}

	void Update() {
		if (Application.isPlaying) return;
		_material.color = TextColor;
	}
}

If you just want to change the color, this will make it:

void OnGUI() {
GUI.contentColor = Color.yellow;
GUI.Button(new Rect(10, 10, 70, 30), “A button”);
}