Last active
August 29, 2015 14:13
-
-
Save soyliquid/83149ecc0c65c962c075 to your computer and use it in GitHub Desktop.
uGUI用タイプライターテキスト ※使用時は各自で適切なAudioSourceを指定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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