problem of setting 3D text color

Hello,
I tried to set the color of 3D text by doing the following:

But the fact is that when I click on the icon of select color, the color panel can’t pop-up. Whenever I click on the color icon, the color will change, but there are only white, black, gray and dark blue. I wonder if I can change into whatever color by script or there are just several color that I can set.

Hi JJ Hou,

I was able to get a color panel and change the color of a 3D font by following these steps: 1) Make the 3D font by selecting the font in the Assets folder and clicking on GameObject, Create Other, 3D Text. This gave me a 3D text object I could then move around and reposition in the scene like any 3D object. (Is this what you meant by 3D text?) 2) Then I created a new material by clicking on Create, New Material. I dragged the font texture from the font asset in the Project Panel to the texture block in this new material. I also changed the material to GUI Text Shader from the default diffuse. This material had a Text Color box that provided a pop-up color panel. I chose a color. 3) Finally, I dragged my new material to the new 3D Text object I had make in the Hierarchy Panel, and my 3D text in the scene changed color. I could also change the text color again by clicking on the Text Color box in the new font material I had made and would get a full pop-up color palette. I got this info from this page in the Unity manual http://unity3d.com/support/documentation/Components/class-Font.html Hope this works for you.

Zaffer

Hi Zaffer. Thank you. I did exactly what you did. But the color panel (Text color) of the material can’t be shown. I don’t know if it is because that I don’t use the professional version.

Hi JJ,

Sorry it didn’t work for you. I am using the free version of Unity, not the pro, so that’s not the problem. The only thing I can suggest is that you experiment a little by perhaps trying a different font and/or going back to the manual page and reading it. You might get an idea from that about what is going wrong.

Zaffer

I find it easier to change text color via scripts, like in this snippet on the unify wiki:

Thanks Technicat,

I tried this and it worked. For a 3D Font (object), make a small script something like this:

function Start () {
	renderer.material.color = Color.blue;
}

And then attached it (drag and drop) to your 3D Font object.

For a GUIText, make a script something like this:

 function Start () {
	guiText.material.color = Color.red;
}

And attach it to your GUIText object.

You don’t have to stick to simple colors like red and blue, you can also put in color numbers, like guiText.material.color = Color(.7, .51, .83); for purple.

Zaffer

And use a code tag instead of a quote when posting your code snippets. Press go advanced and press the # button.

Zaffer, you can also define a public Color variable:

var myTextColor:Color;

and set your material color to that. This will add a color chooser to your script if you don’t want to hardcode it.

Hi Technicat,

I tried this – sounds really cool! But I got this error message:

Here’s my code:

var myTextColor : Color;

function Start () {
	renderer.material.color = Color(myTextColor);
}

Any suggestions? Thanks.

Zaffer

myTextColor is alrady a color object, so there’s no need to construct a color object out of it (and you can’t - check the script reference on Color and see the allowable constructors), so just assign myTextColor:

renderer.material.color = myTextColor;

Also, see the example in http://unity3d.com/support/documentation/ScriptReference/Material-color.html for something fancier.

Hi Zaffer,
The code works for me. Thanks!

Hi technicast,

Thank you! Zaffer’s code works for me. I have another question. I set a prefab of a 3D Text and I want to set it different color in different situation. Are there ways to set the color at runtime?

Hi JJ Hou – glad it worked :slight_smile:

Hi Technicast – Figured it out – very cool, thanks.

Zaffer