using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Printer : MonoBehaviour {
string printer = "有志者事竟成破斧沉舟百二秦关终属楚,\n苦心人天不负卧薪尝胆三千越甲可吞吴。";//待打印的字符串(\n用于换行)
public Text text; //需要打印到的UI
public float delay; //延迟的时间
public int charCount; //一次打印的字节数
int sum = 0; //用于判定是否显示完,和显示的长度
float timer;//计时器
void Update () {
if (sum < printer.Length)
{
timer += Time.deltaTime;
if (timer >= delay)
{
timer = 0;
sum += charCount;
text.text = printer.Substring(0, sum);
}
}
}
}