UGUI打字機效果文本組件
阿新 • • 發佈:2019-03-19
void sys con sharp debug object cond second sha
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TypewriterText : MonoBehaviour { private Text text; private string content; private float delay; // Use this for initialization void Start () { text = gameObject.GetComponent<Text>(); if(text == null) { Debug.LogError("沒添加Text腳本"); } } public void TypeShow(string txt, float _delay=0.5f) { content = txt; delay = _delay; StartCoroutine(AppearText()); } public void AllShow(string txt) { StopAllCoroutines(); text.text = txt; } private IEnumerator AppearText() { char[] arr = content.ToCharArray(); for(int i = 0; i<arr.Length; i++) { text.text += arr[i]; yield return new WaitForSeconds(delay); } } }
UGUI打字機效果文本組件