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
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
| Name | Type | Description |
|---|---|---|
uiText | TMP_Text | The target TMP text UI element. |
textToWrite | string | The full string to reveal. |
CharacterPerSecond | float | Speed 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
| Name | Type | Description |
|---|---|---|
uiText | Text | The target Text UI element. |
textToWrite | string | The full string to reveal. |
CharacterPerSecond | float | Speed of text reveal in characters per second. If set to zero or negative, text is revealed instantly. |
invisibleCharacters | bool | Whether 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.");
}
}