- Home /
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?
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. $$anonymous$$y rule of thumb is to never blame the computer because you just end up being wrong all the time :)
Answer by zoon · Nov 18, 2010 at 05:54 AM
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 $$anonymous$$aterial to the font?
Answer by jonas-echterhoff · Nov 18, 2010 at 10:41 AM
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.
Answer by Lord Moon · Jun 04, 2011 at 04:07 AM
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 ;)
I thought this only worked with dynamic fonts (not available on mobile platforms)?
I tried this on GUITexts and it there was nothing there? There is no attached renderer.
yeh don't change the renderer. Ins$$anonymous$$d just access the material.
var TextToChange : GUIText ; // Drag GUIText here
function Start () {
TextToChange.material.Color = Color.yellow;
}
Answer by Sasa · Aug 02, 2011 at 10:35 AM
This will do :)
var tex : Transform;
function Start() {
tex.guiText.text = "Hello";
tex.guiText.material.color = Color.green;
}
Answer by MaDDoX · Nov 21, 2012 at 07:34 PM
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;
}
}
Your answer
Follow this Question
Related Questions
3d text color 2 Answers
Text/font color 3 Answers
Change text color from event trigger 1 Answer
Text Changes to Black 7 Answers