- Home /
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
Answer by majecty · Nov 18, 2018 at 01:43 AM
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.
Answer by Johnz1234 · Feb 06, 2015 at 10:04 AM
https://www.youtube.com/watch?v=w33cOjMT0fE here is a tutoril :D
Answer by hardmode2236 · Feb 06, 2015 at 09:42 AM
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[c]+"</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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182625im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Text UI is not being assigned 2 Answers
Multiple Rich Text Not Working 1 Answer
Selecting a part of string in input field 1 Answer
Remove the & at the end of concatenated string 0 Answers
Ui text to string ? 1 Answer