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.

1 Answer

1

I created a library for this situation.

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.

I made this code so that an object would move when triggered by the player. but what happens is that it triggers but doesn't move, but the player can manually push the object that's supposed to move.