Trying to identify a single word with TextMesh Pro and changing color

Hello, I’ve been stuck on trying to figure out how to identify characters/words with textmesh pro and then trying to change the color of a single word within the index.

I’ve tried following a text mesh pro video but cant understand it for the life of me… I’m trying to have it so that if an event happens (in this case: Voice cracking) it detects if the player has done the word correctly or incorrectly, colors it accordingly and moves to the next word in the index.

Here’s what I’ve got so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class PaperController : MonoBehaviour
{

    public string inputText;
    public int charPerline;
    public GameObject linePrefab;
    public GameObject spawnLocation;
    public float amountToMoveUpBy;
    public List<GameObject> lines;
    public List<string> separatedInputText;

    public float lerp;
    public float fadeOutAmount;

    private int overStep;
    private int CurrentWordIndex;
    private int currentLineIndex;
    private int CurrentCharacterIndex;
    private int lineListIndex;
    private float curAmountMovedUpBy;
    private float curAmountToMoveTo;

    private int linesAdded;

    // Start is called before the first frame update
    void Start()
    {

        SplitTextLines();
        currentLineIndex = 0;
        CurrentWordIndex = 0;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            if (overStep > 0)
            {
                GameObject newLine = Instantiate(linePrefab, spawnLocation.transform.position, Quaternion.identity, this.transform);
                overStep--;

                Vector3 rot = Vector3.zero;
                rot.x = 90;

                newLine.transform.eulerAngles = rot;

                newLine.GetComponent<TextMeshPro>().text = separatedInputText[lineListIndex];
                lineListIndex++;

                lines.Add(newLine);

                curAmountToMoveTo += amountToMoveUpBy;
                currentLineIndex++;
                linesAdded++;
            }
        }

        int overStepIndex = linesAdded;

       foreach (GameObject line in lines)
       {
            Vector3 movement = Vector3.zero;
            float movementThisTime = Mathf.Lerp(0, curAmountToMoveTo, lerp * Time.deltaTime);

            curAmountToMoveTo -= movementThisTime / lines.Count;

            movement.z += movementThisTime;

            line.transform.localPosition += movement;

            if (overStepIndex > 0)
            {
                Color colorToBe = line.GetComponent<TextMeshPro>().color;
                colorToBe.a -= fadeOutAmount * Time.deltaTime;

                line.GetComponent<TextMeshPro>().color = colorToBe;
            }

            overStepIndex--;
       }

    }

    void SplitTextLines()
    {
        string[] words;

        words = inputText.Split(' ');
        int curCharCount = 0;
        string currentLine = "";

        Debug.Log(currentLine);
        int maxOutIndex = 0;

        foreach (string word in words)
        {
            maxOutIndex++;

            curCharCount += word.Length + 1;
            if (curCharCount > charPerline)
            {
                separatedInputText.Add(currentLine);
                currentLine = word + " ";
                curCharCount = word.Length + 1;
            }
            else
            {
                currentLine += word + " ";
                if (maxOutIndex >= words.Length)
                {
                    separatedInputText.Add(currentLine);
                }
            }
            //Debug.Log(word);
        }

        lineListIndex = 0;
        foreach (string phrase in separatedInputText)
        {
            if (lineListIndex < lines.Count)
            {
                lines[lineListIndex].GetComponent<TextMeshPro>().text = phrase;
                lineListIndex++;
            }
            else
            {
                overStep++;
            }
        }

    }

}

Can anyone help?

Thank you very much!

As you seem to be doing, I’d separate the textmesh text into an array of strings (words). Find the string you want to mark. Append rich-text color formatters on each end of the word , append all the words back together into a single string and assign it back to the textmesh.text