Change Color of Text Mesh Pro via Script

Hi. I want to change the Color of the Text Mesh Pro through Code.
I know that we can simply use .text.color
But, the requirement is to change some characters of the whole text.


Here is my Code:

public TextMehsProUGUI Text;

void Start() {
Text.text = "I want to change THIS"
}

In short, I want to change the color of the word “THIS”.


Thank You for your Time!

@nabeelasad2007

As Text Mesh pro supports rich text, you can use the color tag.

205187-screenshot-2023-03-01-113607.png

try this :

public TextMehsProUGUI Text;
     
     void Start() 
    {
            string color = "blue";
            Text.text = "I want to change" + "<color=" + color + ">THIS</color>";
     }

Yes. I got it. This post is the only one on the Internet with the exact solution.


We must use the HEX Color code instead of </color=red> or any color.