我在Unity中有一个IENumerator,每隔0.70f-0.82f激活一个楼层对象,因此楼层对象之间的间隙是随机生成的。问题是,当有人获得FPS下降时,差距将会很大,而且玩家没有机会进入下一层。我可以使“yield WaitForSeconds”与fps无关吗? 这是代码:
IEnumerator spawnFloors () {
while (playerControll.isAlive) {
for (int i = 0; i < floors.Length; i++) {
spawnWait = Random.Range (0.70f, 0.82f); // 0.65f, 0.85f; aktuell = 0.70f, 0.82f;
Vector2 spawnPosition = new Vector2 (transform.position.x, transform.position.y);
Quaternion spawnRotation = Quaternion.identity;
for (int a = 0; a < floors.Length; a++) {
int randomFloor = Random.Range (0, 9);
if (!floors [randomFloor].activeInHierarchy) {
floors [randomFloor].SetActive (true);
break;
}
}
//Instantiate(floors[Random.Range (0, 3)], spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
}
}`
答案 0 :(得分:2)