StringWriter is a small and efficient C# helper class for Unity that creates a typewriter-style text effect using TextMeshProUGUI.
It gradually displays text character by character, making it ideal for dialogue systems, storytelling UI, loading hints, or any other animated text display.
- Simple setup with just a few lines of code
- Adjustable writing speed
- Optimized with
StringBuilderfor better performance - Fully compatible with Unity Coroutines
- Open source under the MIT License
When you create a StringWriter instance, you provide:
- A TextMeshProUGUI object (the target text element).
- A string containing the text to display.
The coroutine writer() appends one character at a time to the target text element, waiting a configurable amount of time between each update.
By default, each character appears every 0.1 seconds, but you can easily adjust this value.
usingUnityEngine;usingTMPro;usingSystem.Collections;publicclassExampleUsage:MonoBehaviour{publicTextMeshProUGUItextUI;privateStringWriterstringWriter;voidStart(){// Create a new StringWriter instance with the target text object and messagestringWriter=newStringWriter(textUI,"Hello, this is a typewriter text effect!");// Start the coroutine at 0.05 seconds per characterStartCoroutine(stringWriter.writer(0.05f));}}