Changing text color while writing it one character at a time in a text field.
Hi!
I'm developing a game with a text box based dialogue system, like old jrpgs. I read the dialogue text from file and I write it one character at a time in a text field. If the player clicks a button, the entire line appears instantly.
I'm now trying to give more visual options to the text. I want to color only some words of a sentence. If I change the text field color it obviously works, but it applies the color to the whole field. If I use tags, it works when the whole sentence is written but it doesn't work while the text is showing one chararacter at a time.
I thought I could "read" the tag one character at a time while I'm displaying the text, ignore its characters and apply the color to what comes after it, but I don't know how I could apply the color to that.
How can I refer to some specific part of a text field so that I don't apply the color to the whole field?
This will also help me changing only some words text size.
Thank you in advance!
Luca.
Answer by majecty · Nov 18, 2018 at 01:38 AM
I created a library for this situation.
https://github.com/majecty/Unity3dRichTextHelper
var richText = "<color=blue>blue</color>black";
richText.RichTextSubString(3); // <color=blue>blu</color>
richText.RichTextSubString(6); // <color=blue>blue</color>bl
You can use the tag and display the text one character at a time correctly.
Your answer
Follow this Question
Related Questions
I can't change Text color 3 Answers
Working with the GUI 4.6 (textfields and buttons) 1 Answer
TextField does not update in Game 1 Answer
UI text wont highlight 0 Answers
Text Boxes Not Visible 0 Answers