How can I change the colour of individual characters in a text string
I simply have a paragraph of text and in my C# script I want to change the colour of individual letters at a specific index.
For example, my paragraph is rendered white on a white background and I want to turn each letter to black starting from the first and going through to the end.
I'm using a loop and I want to do something like this:
for (int i = 0; i < stringLength; i++) { myText.text[i].color = black; }
Now I can read each letter by using
Debug.Log(myText.text[i]);
so shouldn't it be really simple to just edit the colour of the letters at those indices?
Answer by doublemax · Oct 31, 2016 at 11:18 PM
It doesn't work that way.
Which component do you use to display the text? If it's UI.Text, you can use markup to display rich text which allows to color the text.
https://docs.unity3d.com/550/Documentation/Manual/StyledText.html
Answer by Nedgoom · Nov 01, 2016 at 12:14 AM
Thanks for the quick answer, yes it's UI.Text.
How would I go about using tags to change each character's color? I've seen people using Replace but that seems to change all letters of one type, eg it would go through and change each "A" to a "B" or whatever you specified.
I just want to go, render first char black, then render second char black, etc.