Hey, I think @KayelGee was on the right lines, though I think we can make it a little more generic. The below code compares the previous character to the current one and increments an index. This index is used to lookup colour names (this is the bit I don’t like much, maybe use Color objects and convert to Hex). Then I use string.Format to create the actual marked up text substituting in the colour and character.
GUIText wordText = new GUIText();
wordText.richText = true;
string obj = "COFFEE";
string formattedText = "";
public string[] colours = new string { "red", "yellow", "blue", "pink" };
char[] w = obj.ToCharArray();
char previous = w[0];
int colourIndex = 0;
for(int x = 0; x < w.Length; x++)
{
// If there's a new character get the next colour
if(w[x] != previous)
{
colourIndex++;
if(colourIndex >= colours.Length) { colourIndex = 0; }
}
formattedText += string.Format("<color={0}>{1}</color>",
colours[colourIndex], w[x]);
}
wordText.text = formattedText;