Skip to main content

Class TextWriter

A helper class that provides typewriter-style text reveal animations for text related UI elements by utilizing DOTween to progressively reveal characters at a defined speed.

public static class TextWriter

Inheritance​

object→TextWriter

Methods​

AddWriter(TMP_Text, string, float)​

Applies a typewriter effect to a TMPro.TMP_Text element, revealing text over time.

public static float AddWriter(TMP_Text uiText, string textToWrite, float CharacterPerSecond)

Parameters​

NameTypeDescription
uiTextTMP_TextThe target TMP text UI element.
textToWritestringThe full string to reveal.
CharacterPerSecondfloatSpeed of text reveal in characters per second. If set to zero or negative, text is revealed instantly.

Returns​

float — Total duration of the animation in seconds.

Examples​

using UnityEngine;
using TMPro;

public class TMPTypewriterExample : MonoBehaviour
{
[SerializeField] private TMP_Text dialogueText;

private void Start()
{
string message = "Welcome, traveler! Your journey begins here...";
float duration = TextWriter.AddWriter(dialogueText, message, 25f);
Debug.Log($"Typewriter animation will complete in 25 seconds.");
}
}

AddWriter(Text, string, float, bool)​

Applies a typewriter effect to a UnityEngine.UI.Text element, revealing text over time with optional invisible trailing characters.

public static float AddWriter(Text uiText, string textToWrite, float CharacterPerSecond, bool invisibleCharacters = false)

Parameters​

NameTypeDescription
uiTextTextThe target Text UI element.
textToWritestringThe full string to reveal.
CharacterPerSecondfloatSpeed of text reveal in characters per second. If set to zero or negative, text is revealed instantly.
invisibleCharactersboolWhether to display unrevealed characters as invisible placeholders to maintain layout consistency.

Returns​

float — Total duration of the animation in seconds.

Examples​

using UnityEngine;
using UnityEngine.UI;

public class LegacyTextTypewriterExample : MonoBehaviour
{
[SerializeField] private Text notificationText;

private void Start()
{
string message = "Loading assets...";
float duration = TextWriter.AddWriter(notificationText, message, 20f, true);
Debug.Log($"Legacy text typewriter effect duration: 20 seconds.");
}
}
  • Methods
    • AddWriter(TMP_Text, string, float)
    • AddWriter(Text, string, float, bool)