赞
踩
在unity里面文字随时间逐个出现的效果,代码如下:
public class gamebeijin : MonoBehaviour { public float textShowTime_Second = 0.2f; private string content = "传说,在远古的时候,天地之间只有几丈高,天上有七个太阳和七个月亮,太阳把大地烧得滚烫烫的。百姓叫苦连天。这时有一个黎族大力神挺身而出......"; public bool isActive = false;//是否正在输出 private float timeCount; public Text targetText; private int currentPos = 0; void Update() { StartCoroutine(StarWrite()); } [ContextMenu("TestShow")] public float StarShow(string str) { timeCount = 0; isActive = true; content = str; targetText.text = ""; return timeCount * content.Length; } public void OffShow() { isActive = false; timeCount = 0; currentPos = 0; targetText.text = content; } IEnumerator StarWrite() { if (!isActive) yield break; timeCount += Time.deltaTime; if (timeCount >= textShowTime_Second) { timeCount = 0; currentPos++; if (currentPos > content.Length) { OffShow(); } else { targetText.text = content.Substring(0, currentPos); } } } }
喜欢的点个赞再走呗!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。