好幾乎我想要做的是讓我的程序等待預定的時間,然後將字符移動到網格上的另一個點(它由「panel_x」和「panel_y」變量標記)。相反,它會等待,然後移動每個框架周圍的角色...我不知道我做錯了什麼。我相信我需要一個協程,但我可能是錯的。爲什麼我的程序不能像我需要的那樣等待?
//How I am calling the coroutine
void Update()
{
if(HP != 0)
{
StartCoroutine(Wait());
}
}
//The Coroutine I need to run to move my character
//around...I need this to run until the character's
//hp reaches 0.
IEnumerator Wait()
{
while(true)
{
//I need it to wait...
yield return new WaitForSeconds(3);
//Then move the character to another
//grid...
panel_x = Random.Range(1, 4);
panel_y = Random.Range(1, 4);
}
}
謝謝!我的Twitter上的某個人告訴我只需將StartCoroutine放入啓動方法中即可使用,但這個提示給我很多次,所以下次我需要使用這種方法! –