UGUI打字机效果
程序员文章站
2022-06-22 20:01:43
...
using UnityEngine;
using UnityEngine.UI;
public class TypeEffect : MonoBehaviour {
float letterpause = 0.2f;
AudioClip clip;
private string word;
private string text = "sdfdsgfghrturjhgfbsgdasf";
public Text showtext;
// Use this for initialization
IEnumerator Start () {
word = text;
text = null;
yield return new WaitForSeconds(2f);
StartCoroutine (TypeWord());
}
IEnumerator TypeWord()
{
foreach (var item in word.ToCharArray())
{
showtext.text += item;
this.GetComponent<AudioSource>().PlayOneShot(clip, 1f);
yield return new WaitForSeconds(letterpause);
}
}
}