5
\$\begingroup\$

In Unity 5 on Windows 10, I try to change the text color from the Inspector and in scripts, but the color won't change. Here are some screenshots of my Text objects open in the inspector, with there colors set to red and white, but staying the default black in the Scene and Game windows:

Continue Text

Score Text

Here are the lines of code I am using to change the color

var textColor = beatBestTime ? "#FF0" : "FFF";

scoreText.text = "Time " + FormatTime (timeElapsed) + "\n<color="+textColor+">Best " + FormatTime (bestTime)+"</color>";

which I can verify are being run, but the color remains the same!

\$\endgroup\$
  • \$\begingroup\$ Hmm, well according to the documentation, I would expect to see var textColor = beatBestTime ? "#FFFF00" : "#FFFFFF";. Notice the use of the # in both of the strings, and the usage of the full 6 characters. I'm not entirely sure this is what would fix your issue, but it would be more like what the engine expects. \$\endgroup\$ – Alexandre Vaillancourt Feb 9 '16 at 2:31
  • \$\begingroup\$ I don't think that is the problem, however I did try it and nothing has changed. \$\endgroup\$ – jasper Feb 9 '16 at 2:39
3
\$\begingroup\$

I got stuck on this same thing in this tutorial. My fix was to assign the font material to the text component's material directly underneath where you change it red.

\$\endgroup\$
1
\$\begingroup\$

Like user @JaredBrowne says, just go ahead and add the material that was created when you made the "Create Edible Copy".

enter image description here

\$\endgroup\$
0
\$\begingroup\$

If it's a bitmap font, you need to make sure that the letters in the sprite sheet are white so that colors will be applied correctly with Unity's default text shader. Most tools, including Unity's "Create Editable Copy," create black letters, but this will lead to the exact symptoms you describe. If you have an existing sprite sheet with black letters, you can just do a quick color replacement in your editor of choice.

\$\endgroup\$
  • \$\begingroup\$ it is a .ttf file, I assume this is not a bitmap font? \$\endgroup\$ – jasper Feb 9 '16 at 3:15
  • \$\begingroup\$ @jasper I've not seen this happen with a TTF, but the process I alluded to would probably work for you. Go to Import settings for the TTF in Unity, hit the gear in the top right, and do "create editable copy." You'll have to fiddle the settings to make it work (hinted raster, ascii default.) Then set that copy as the font for your text, and update the spritesheet that it spit out to have white letters instead of black. If your text still does't colorize, there's likely a shader/material issue. \$\endgroup\$ – Nox Feb 9 '16 at 15:07
  • \$\begingroup\$ Along this line of reasoning, try changing the font temporarily to Arial (or something else built-in) to see if it helps. Should tell you whether there's something awry in the font file or elsewhere in your code/scene. \$\endgroup\$ – Chris Mills-Price Feb 9 '16 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.