【发布时间】:2014-06-06 19:27:59
【问题描述】:
所以我试图在一个while循环中消灭敌人,中间等待1秒(他们会让等待更难吗??)问题是,所有敌人都被同时消灭,他们没有等待WaitForSEconds。 在我的 while 循环中,我通过标签调用每个敌人,标签从 Enemy1 到 Enemy5。 这是我的代码。
void OnTriggerEnter(Collider otherObject)
{
int i=1;
while (i<=numenemies)
{
string tag="Enemy"+i;
destroyenemy=GameObject.FindGameObjectWithTag(tag);
Destroy(destroyenemy);
i++;
StartCoroutine(DestroyWait ());
}
}
IEnumerator DestroyWait()
{
Debug.Log ("so far...");
yield return new WaitForSeconds (1);
Debug.Log ("so good");
}
在我的调试日志中的控制台中,我得到 4 个“到目前为止...”,然后是 4 个“非常好”。它不等待 1 秒然后输出这么好。
我一直在阅读这方面的内容,而且很难将脚本暂停 1 秒钟!我做错了什么?
【问题讨论】:
-
@YuvalItzchakov 不,它会停止游戏
标签: c# unity3d wait ienumerator