rich text issue

i’m working with a UI.text element and i have the rich text checked, but i’m using a little function that types out strings character by character with a little pause inbetween. I wanted to color code the NPCs dialogue in my game and when i have it write out something like:

"<color=#75A3FF>blah blah blah</color>"

it writes the text out, but the string i’m writing the characters to wont understand the HTML color code until the very end when i reach the ending color brackets, then once its all typed out, it recognizes the color coding and it corrects itself. but until then i can see the function typing everything out. does anyone know a way around this?

maybe i could input the entire color code first, then type the characters into the middle of it?
but i don’t know how i would go about that. maybe using substrings?

  • ill be trying to do this with substrings unless someone else and give me a better route

I created a simple library for this issue.

With the library you can get substring of rich text using simple function.

var richText = "<color=blue>blue</color>black";
richText.RichTextSubString(3); // <color=blue>blu</color>
richText.RichTextSubString(6); // <color=blue>blue</color>bl

You can download it in the below link.

[Unity 4] Creating a simple countdown timer (JavaScript) - YouTube here is a tutoril :smiley:

Ok as it turns out this wasn’t as bad as i thought it was going to be. i just use this code:

textBox.text +=code;
while(count<s.Length)
	{
		//cut the code in between code brackets
		textBox.text = textBox.text.Substring(0, textBox.text.Length-8);
		//put in the letter and the ending bracket
		textBox.text += s
+"</color>";
			count++;
			yield WaitForSeconds(.02);
    	}

this works, but i'm wondering if there's a more elegant solution. otherwise this just has to keep cutting and adding that ending HTML code to the end of the string every letter.