如何使脚本以统一的简单方式等待/睡眠

如何使脚本以统一的简单方式等待/睡眠

如何在TextUI.text = ....睡眠功能之间放置,每个短语之间等待3秒?


public Text GuessUI;

public Text TextUI;


[...truncated...]


TextUI.text = "Welcome to Number Wizard!";

TextUI.text = ("The highest number you can pick is " + max);

TextUI.text = ("The lowest number you can pick is " + min);

我已经尝试了各种各样的东西,但没有奏效,这样:


TextUI.text = "Welcome to Number Wizard!";

yield WaitForSeconds (3);

TextUI.text = ("The highest number you can pick is " + max);

yield WaitForSeconds (3);

TextUI.text = ("The lowest number you can pick is " + min);

在bash中将是:


echo "Welcome to Number Wizard!"

sleep 3

echo "The highest number you can pick is 1000"

sleep 3

.....

但我无法弄清楚我是如何在Unity中用C#做的


心有法竹
浏览 403回答 3
3回答

回首忆惘然

你使用WaitForSeconds是正确的。但我怀疑你尝试使用它没有协同程序。它应该如何工作:public void SomeMethod(){     StartCoroutine(SomeCoroutine());}private IEnumerator SomeCoroutine(){     TextUI.text = "Welcome to Number Wizard!";     yield return new WaitForSeconds (3);     TextUI.text = ("The highest number you can pick is " + max);     yield return new WaitForSeconds (3);     TextUI.text = ("The lowest number you can pick is " + min);}
打开App,查看更多内容
随时随地看视频慕课网APP