Unity3D中的WaitForSeconds

时间:2015-04-19 14:21:29

标签: c# unity3d frame-rate ienumerator

我在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);


                    }
            }

    }`

1 个答案:

答案 0 :(得分:2)

您是否考虑过使用FixedUpdate()

如果您想知道what's the difference,则团结a tutorial for it

它仅用于游戏中与帧无关的更新。