【发布时间】:2019-07-28 01:44:52
【问题描述】:
我正在生成预制件并使用协程,但我可以看到在 yield return new WaitForSeconds(2.3f); 之前运行的函数的预制件之间存在随机延迟或空间间隙;
IEnumerator SpawnObject()
{
while (true)
{
GameObject screenShape = (GameObject)Instantiate(screenlines, new Vector3(ShapespawnerObjPos.transform.localPosition.x, shapeposition[GetFirstIndexlistofIntShapePosition()], ShapespawnerObjPos.transform.localPosition.z), transform.rotation);
//function get random number with checking called here
yield return new WaitForSeconds(2.3f);
}
}
我打算做的是执行函数获取随机数,并在 WaitForSeconds() 期间检查而不是在它之前以避免预制件之间的随机空间间隙。
【问题讨论】:
-
对不起,我没有关注。检查随机数与
WaitForSeconds有什么关系? -
我只是想在协程等待期间运行一个函数
-
这正是等待不工作的方式。您可能可以使用 lambda 匿名函数使用
WaitWhile或WaitUntil来解决它,然后您必须手动计算时间。 -
为什么不将函数写入另一个协程并在
WaitForSeconds之前启动该协程?
标签: c# unity3d game-development