3
2015
UI Text TypeWriter Effect [Script]
Quick & simple UI text typewriter effect (displays UI text 1 character at a time)
Assign to UI text component, it grabs the text from it at Awake() and clears it,
then starts to type out the text 1 character at a time.
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
// attach to UI Text component (with the full text already there) | |
public class UITextTypeWriter.cs : MonoBehaviour | |
{ | |
Text txt; | |
string story; | |
void Awake () | |
{ | |
txt = GetComponent<Text> (); | |
story = txt.text; | |
txt.text = ""; | |
// TODO: add optional delay when to start | |
StartCoroutine (PlayText()); | |
} | |
IEnumerator PlayText() | |
{ | |
foreach (char c in story) | |
{ | |
txt.text += c; | |
yield return new WaitForSeconds (0.125f); | |
} | |
} | |
} |
More versions, see comments:
https://gist.github.com/unitycoder/19625fed364a39cb278f
Related Posts
15 Comments + Add Comment
Leave a comment
Recent posts
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
LifeSaver. thank you
Then where the link ? how can i download it??
Full script source is ^up there in the post,
but also here (someone has actually made improved version there with more options, see the comments on that page)
https://gist.github.com/unitycoder/19625fed364a39cb278f#file-uitexttypewriter-cs
[…] UI Text TypeWriter Effect | Unity Coding (unitycoder.com) […]
Really useful! Thanks!
[…] UI Text TypeWriter Effect | Unity Coding (unitycoder.com) […]
hey, i want to make if u press a mouse button the whole text appears, how do i make that happen?
you could probably just have a var for the entire text and then make that show instead when the player presses a button
Thank!
THANKS SO MUCH! I’ve been searching for hours to find this simple solution. Thanks!
Thank you, worked like a charm!
LoL, nice start, but reading the github code suggestion/improvements makes me facepalm a lot.
Any delay can be added inside the coroutine, no need for multiple calls, no need to convert commas or dots, just compare the char dirrectly…
thank you! you’re the only one who made a script that actually works!
oh ohh ohhohoh it works.
How do I take away each character, doing a -= operator does not work.