首页 > 其他 > 详细

UGUI打字机效果文本组件

时间:2019-03-19 18:33:38      阅读:170      评论:0      收藏:0      [点我收藏+]
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打字机效果文本组件

原文:https://www.cnblogs.com/ssw-men/p/10560463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!