Guide:Unity 3D GUI

From Game Making Tools Wiki
Revision as of 15:23, 16 October 2016 by Rjt (talk | contribs) (Created page with "==TypeWriterEffect.cs== Here's a kinda clunky little typewriter effect I found somewhere. Still trying to fidn where so I can give credit :( I've modified it ''slightly''. <p...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

TypeWriterEffect.cs

Here's a kinda clunky little typewriter effect I found somewhere. Still trying to fidn where so I can give credit :( I've modified it slightly.

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

public class TypeWriterEffect : MonoBehaviour {

	public float delay = 0.1f;
	[TextArea(4,10)]
	public string fullText;
	private string currentText = "";

	void Start () {
		StartCoroutine(ShowText());
	}

	IEnumerator ShowText(){
		for(int i = 0; i < fullText.Length; i++){
			currentText = fullText.Substring(0,i);
			this.GetComponent<Text>().text = currentText;
			yield return new WaitForSeconds(delay);
		}
	}
}