Unity 入门打字机效果
使用协程加延迟
public class UIDazhi : MonoBehaviour
{
public Text t;
//private string currentstr = "";
public string str = "欢迎来到Unity的世界";
// Start is called before the first frame update
void Start()
{
Debug.Log("12");
t.text = "";
StartCoroutine( Fade());
}
IEnumerator Fade()
{
yield return null;
for (int i = 0; i <= str.Length; i++)
{
Debug.Log("sadf");
t.text = str.Substring(0, i);
yield return new WaitForSeconds(0.5f);//延迟0.5秒
}
}
// Update is called once per frame
void Update()
{
}
}