Reputation: 255
I have an IENumerator in Unity wich activates a floor object every 0.70f-0.82f, so the gaps between the floor objects are randomly generated. The problem is, that when someone gets an FPS drop, the gaps are going to be huge and they player has no chance to reach the next floor. Can I make the "yield WaitForSeconds" fps-independent? This is the code:
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);
}
}
}`
Upvotes: 1
Views: 440
Reputation: 3463
Have you considered using FixedUpdate()
instead?
In case you are wondering what's the difference, unity has a tutorial for it.
It's simply used for frame-independent updates in your game.
Upvotes: 2