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 to テキストを表示する方法 [Unity] – Site-Builder.wiki
Recent posts
- 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
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
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.