using UnityEngine;
using System.Collections;
using UnityEngine.UI;
/// <summary>
/// 打印机特效控制脚本
/// </summary>
public class TypewriterEffect : MonoBehaviour
{
public float charsPerSecond = 0.2f;//打字时间间隔
private string words;//保存需要显示的文字
private bool isActive = false;
private float timer;//计时器
private Text myText;
private int currentPos = 0;//当前打字位置
// Use this for initialization
void Start()
{
timer = 0;
isActive = true;
charsPerSecond = Mathf.Max(0.2f, charsPerSecond);
myText = GetComponent<Text>();
words = myText.text;
myText.text = "";//获取Text的文本信息,保存到words中,然后动态更新文本显示内容,实现打字机的效果
}
// Update is called once per frame
void Update()
{
OnStartWriter();
//Debug.Log (isActive);
}
public void StartEffect()
{
isActive = true;
}
/
Unity 文本实现打印机效果
最新推荐文章于 2024-07-23 18:36:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)