Last active
April 11, 2024 08:11
-
-
Save unitycoder/19625fed364a39cb278f to your computer and use it in GitHub Desktop.
Type out UI text one character at a time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a simplier approach, without audio