Unity while
在迭代器中使用while 导致ide挂起。
比如
IEnumerator Test()
{
yield return new WaitForSeconds(2);
Debug.Log("return null");
StartCoroutine(this.Test());
Debug.Log("retuen 2s");
yield return null;
while (true)
{
Debug.Log("i am while");
}
}
避免以上的用法
应该如此
while (spawnRigidbody2D!=null)
{
if (!isFaceRight)
{
if (spawnRigidbody2D.transform.position.x < this.LeftSpawnX - 0.5)
{
Destroy(spawnRigidbody2D.gameObject);
}
}
else
{
if (spawnRigidbody2D.transform.position.x > this.RightSpawnX + 0.5)
{
Destroy(spawnRigidbody2D.gameObject);
}
}
yield return null;
}
在while中使用yield return null
如果使用while就是阻塞主线程吧。

浙公网安备 33010602011771号