how did change color of specific words in auto filling text????

hi every one and happy new year
so i want to make aboss intro with auto filling text and i made this code

public class Dialogue : MonoBehaviour
{
public TextMeshProUGUI textDisplay;
public string sentences;
private int index;
public float typingSpeed;


private void Start()
{
    StartCoroutine(Type());
}
IEnumerator Type()
{
    foreach (char Letter in sentences[index].ToCharArray())
    {
        textDisplay.text += Letter;
        yield return new WaitForSeconds(typingSpeed);
    }
    NextSentenceAuto();
}
public void NextSentenceAuto()
{
    if (index < sentences.Length-1)
    {
        index++;
        textDisplay.text = "";
        StartCoroutine(Type());
    }
    else
    {
        textDisplay.text = "";
    }
}

but i want to make the first word or so as the (boss name in red color or so)and the rest in normal color
like BOSSNAME(in red):I will KILL YOU (white)

Bossname: i will kill YOU


please help and THANKS

There’s an easier way to do all of that since you’re already using TextMeshPro. First, TMP text controls have a maxVisibleCharacters field that you can use. My dummy script will use:

IEnumerator Type(string content, float speed)
{
    this.textMeshPro.maxVisibleCharacters = 0;
    this.textMeshPro.text = content;

    var parsedContent = this.textMeshPro.GetParsedText();
    var yieldInstruction = new WaitForSeconds(speed);

    while (this.textMeshPro.maxVisibleCharacters < parsedContent.Length)
    {
        yield return yieldInstruction;
        this.textMeshPro.maxVisibleCharacters++;
    }
}

For colored content, check out the Rich Text documentation for TMP. With that, we can do something like:

var content = $"<color=red>Boss:</color> You can even <size=15>change the size</size>";

this.StopAllCoroutines();
this.StartCoroutine(this.Type(content, this.typingSpeed));

to get the following:

151109-tmp.gif