Unity实现文字打印效果
效果图:

思路比较简单:
- 准备一段需要输出打印的文本
- 存入char[]中
- 以一定的时间间隔将char[]中的值累积
- 输出累积的字符串
代码:
private string myString = "需要打印的字符串";
private float showTime = 0.2f; //间隔时间
private char[] cTest = null; //存储字符串
private int indexCount = 0; //累积计数
public void Update()
{
showTime -= Time.deltaTime;
if (showTime <= 0 )
{
if (cTest != null && indexCount < cTest.Length)
{
txtContent.text += cTest[indexCount];
indexCount++;
showTime = 0.2f;
}
}
}
//注意下一次打印时需要清空显示的控件值、存储字符串char[]值、累积计数
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭