[英]Unity script - code is executed no in oder. How do I turn off multithreading?
代碼未按順序執行是什么意思。 我有以下代碼:
IEnumerator Game(){
// do something
yield return new WaitForSecondsRealtime(10f);
// do something else
Debug.Log("game method")
}
void Start(){
// some code ..
StartCoroutine(Game());
// other code ..
Debug.Log("end of the code");
Debug.Log("something else");
}
出於某種原因,我會在控制台中得到這個:
end of the code
something else
game method
我想這與多線程有關。 我如何關閉它(我如何避免它)?
它按順序執行。
你的代碼應該是這樣的:
void Start()
{
StartCoroutine(Game());
}
IEnumerator Game(){
// do something
yield return new WaitForSecondsRealtime(10f);
// do something else
Debug.Log("game method")
ExecuteLast();
}
void ExecuteLast()
{
Debug.Log("end of the code");
Debug.Log("something else");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.