using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class xianshi : MonoBehaviour
{
public Text text;
public Button button;
private string tex;
bool boo=true;
char[] cha;
int id = 0;
public void fang()//button方法
{
if (boo)
{
boo = false;
kaishi();
}
}
private void kaishi()
{
text.text = "";
tex = "你好世界";
cha = tex.ToCharArray();//将string里每一个字符转化为cha
StartCoroutine(Tex());//开始显示
}
IEnumerator Tex()
{
bool b = true;
while (b)
{
for (int i = 0; i < cha.Length; i++)
{
yield return new WaitForSeconds(0.2f);//每0.2秒出现一个
text.text += cha[i];
if (i>=3)//超出tex长度停止协程
{
StopAllCoroutines();
}
}
}
}
}