Skip to content

Instantly share code, notes, and snippets.

@eiyaya
Forked from unitycoder/UITextTypeWriter.cs
Created February 25, 2020 23:58
Show Gist options
  • Save eiyaya/3ca397af8525ad85c4734e7b7e7b130b to your computer and use it in GitHub Desktop.
Save eiyaya/3ca397af8525ad85c4734e7b7e7b130b to your computer and use it in GitHub Desktop.
Type out UI text one 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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment