UGUI打字机效果

来源:互联网 发布:淘宝企业账号审核 编辑:程序博客网 时间:2024/06/04 21:10
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);        }    }}
原创粉丝点击