Code automatic text writter for Unity UI

This is a general version of the code used on Clarisse to write text giving the impresion that you are typing.
We use a Text object (UI) at the scene as output for the string and a coroutine call to write characters every “velocity” seconds, depending of that variable.

Result:

 

 

Code:

 

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class TextWriter : MonoBehaviour {

	
    public Text Interface; //We are using Unity UI System for write our text.
	public string chain; //Text to show.
	private float velocity = 0.02f; //Velocity between each letter.


    void Start () {
        StartCoroutine(WriteChain(chain));
    }
	
    IEnumerator WriteChain(string chain)
    {
        while (chain.Length > 0)
        {
            Interface.text += chain.Substring(0,1); //Write first letter in chain.
            chain = chain.Substring(1, chain.Length -1); //We take the rest in chain, less the first letter.
            yield return new WaitForSeconds(velocity);
        }
    }
}

 

Feel free to contact us if you have any questions.

 

@metalDelVer