好几乎我想要做的是让我的程序等待预定的时间,然后将字符移动到网格上的另一个点(它由“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放入启动方法中即可使用,但这个提示给我很多次,所以下次我需要使用这种方法! –