Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
    
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. – Alexandre Vaillancourt Feb 9 at 2:31
    
I don't think that is the problem, however I did try it and nothing has changed. – jasper Feb 9 at 2:39

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.

share|improve this answer
    
it is a .ttf file, I assume this is not a bitmap font? – jasper Feb 9 at 3:15
    
@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. – Nox Feb 9 at 15:07
    
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. – Chris Mills-Price Feb 9 at 21:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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