Skip to content

Instantly share code, notes, and snippets.

@soyliquid
Last active August 29, 2015 14:13
Show Gist options
  • Save soyliquid/83149ecc0c65c962c075 to your computer and use it in GitHub Desktop.
Save soyliquid/83149ecc0c65c962c075 to your computer and use it in GitHub Desktop.
uGUI用タイプライターテキスト ※使用時は各自で適切なAudioSourceを指定
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
[RequireComponent(typeof(Text))]
public class UITypeWriterText: MonoBehaviour {
private Text targetUIText;
private string textCache;
public float Speed = 0.2f;
public AudioClip TypeSound;
public AudioClip TypeFinishedSound;
void Awake() {
targetUIText = GetComponent<Text>();
textCache = targetUIText.text;
targetUIText.text = "";
}
void Start () {
StartCoroutine(ProcessType());
}
IEnumerator ProcessType () {
// type text till done all.
while(targetUIText.text.Length < textCache.Length) {
targetUIText.text += textCache[targetUIText.text.Length];
if(TypeSound != null) {
AudioManager.Instance.Play(TypeSound);
}
yield return new WaitForSeconds(Speed);
}
if(TypeFinishedSound != null) {
AudioManager.Instance.Play(TypeFinishedSound);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment