Text Mesh Pro

Hello,
I found a script to make my Text show letter by letter, but i can’t find one to make the same thing with TMP. Can anyone help me with that ?

What class does it use to display the text right now?

If it is the one from UnityEngine.UI then you can just change it to use the TextMeshPro class you want, either the one that uses a Canvas (UGUI) or the bare one.

This is the code, I tried to change the “[RequireComponent(typeof(Text))]” to “[RequireComponent(typeof(TextMesh))]”
but when the script run there is errors.

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Text))]
public class LoadText : MonoBehaviour
{

    private Text uiText;

    private float showSpeed = 0.05f;

    private string showText, uiTextCopy;

    private bool coroutineProtect, loadText;


    private void Start()
    {
        uiText = GetComponent<Text>();

        TextInformations();
    }

    private void OnEnable() { uiTextCopy = null; }

    private void Update()
    {
        if (loadText && !coroutineProtect)
        {
            StartCoroutine(LoadLetters(uiTextCopy));
            coroutineProtect = true;
        }

        else if (loadText && coroutineProtect) { uiText.text = showText; }

        else if (!loadText && !coroutineProtect)
        {
            if (uiText.text != uiTextCopy) { TextInformations(); }
        }
    }

    private void TextInformations()
    {
        uiTextCopy = uiText.text;
        showText = null;
        uiText.text = null;

        loadText = true;
        coroutineProtect = false;
    }

    private IEnumerator LoadLetters(string completeText)
    {
        int textSize = 0;

        while (textSize < completeText.Length)
        {
            showText += completeText[textSize++];
            yield return new WaitForSeconds(showSpeed);
        }

        coroutineProtect = false;
        loadText = false;
    }

}

While I admire your adventurous spirit, you want to at least get a passing familiarity with the stuff you’re trying. :slight_smile:

The TextMesh class is the ancient non-canvas way of displaying Text and has nothing to do with TextMeshPRO.

If you want to apply what I suggest above, the class you (probably) want is TexMeshProUGUI. Don’t forget to add the correct using for TMPro.

Im new to Unity and C# :sweat_smile:
Thank you for your advices. I’ll try that.

1 Like

Welcome! Looking at the above code, it does not seem to properly handle rich text, which TMPro and Text supports. For instance if you embedded bold or underlined or COLORED text, it will not work properly.

My typewriter package (attached) does handle this. If you don’t need that stuff, don’t bother.

If you wanted to upgrade it to TMPro, same steps apply as the above. Full comments in the code.

8683470–1170801–TypewriterWithHTMLStrings.unitypackage (5.17 KB)

Wow ! Thank you so much
I’ll try later, I can’t now

WOW, it works !!!
Thank you so much !!!

1 Like