How to change the color of an element of a String Array in Unity

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 = “<color=blue>R”;
the value of that index, as it’s clear, also changes to the value of “<color=blue>R”.
So, whenever I call this value again, as the value of that index, I get the output of: “<color=blue>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?

Separate the actual meaningful data contents of the string (in this case your “R”) from the presentation (i.e., the addition of color). This means you need a separate way to store the “R” and what color it should be, and then a step that produces the rich text when it needs to go to the Text object.

1 Like

There are a lot of misconceptions and inconsistencies in your question.
While I think I understand in general what you’re trying to achieve, I can’t tell exactly what you did and what went wrong.
By using “RichText” I presume you mean that you’ve activated the rich text option.
By setting string array I presume you mean setting a particular string in an array.
Is it editor GUI, is it UI Elements, is it legacy in-game Unity UI, or is it TextMeshPro (also known as TMP)?
You need to be much more precise in order to get your issue solved.

Thank you for your comment. I used UI Elements and created a Text in the scene. My text object has a value and I get that text value inside of a string array. Then I want to change the color of the some elements which are inside of the array. In my case, I want to change the color of “R” which is in the index of 1. Now I want to change it but when I change it and assign it to the original text object as the value of it, it includes the rich text tags which I don’t want to have and is my issue.

Okay. This is what I managed to dig up, regarding UIElements.
I haven’t used the library yet so I don’t have any firsthand experience.