How to change the color of an element of a StringArrayin Unity

0

I want to change the color of a particular element inside of a string array in Unity, C#.

When I try to use “RichText” the value of that element also changes.

For instance when I use

stringArray = “R”;
the value of that index, as it’s clear, also changes to the value of “R”.
So, whenever I call this value again, as the value of that index, I get the output of: “R”
I also tried to use Replace method but the result is the same.
How can I change the particular color of an element in an array in Unity?

A string is a string, it does not have color.

If you don’t want to or can’t have the rick text tags inside the string itself, you will need another way to format your string.

There are multiple ways to approach this.

The most straightforward way to approach this is to have another array containing the color to apply:

stringArray *= "R";*

colorArray = Color.red;
string output = string.Format(“<color=#{1}>{2}”, ColorUtility.ToHtmlStringRGBA(colorArray_), stringArray*);*_