UGUI打字机效果

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);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/z502768095/article/details/78041385
今日推荐