Dec
3
2015

UI Text TypeWriter Effect [Script]

UI_typewriter_effect

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.

UI_typewriter_effect_script

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


15 Comments + Add Comment

  • LifeSaver. thank you

  • Then where the link ? how can i download it??

  • […] 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.

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch Instagram

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.