IEnumerator RunLevelStep(int level) { Debris.salvaged = 0; Debris.total = 0; run_level = level; int current_level = level; GM.player.transform.x(0f); foreach (string level_seed_string in level_seeds[current_level].Split(new char[] { '|' })) { GM.player.recharges = 0; int level_seed = int.Parse(level_seed_string); playing = false; ground_collider.enabled = true; yield return(new WaitForSeconds(generate_delay[current_level])); List <Debris> generated_debris = GenerateDebrisFromSeed(current_level, level_seed); foreach (Debris d in generated_debris) { d.Initialize(); } yield return(null); foreach (Debris d in generated_debris) { d.Fly(); yield return(new WaitForSeconds(generate_delay[current_level])); } trash_routine = StartCoroutine(GenerateTrashDebris(current_level)); yield return(trash_routine); while (Debris.any_flying) { if (Input.GetKey(KeyCode.I)) { Debug.Log("still flying"); } yield return(null); } yield return(new WaitForSeconds(1f)); ground_collider.enabled = false; while (GM.player.warudo) { yield return(null); } GM.Tick(); Debris.StartCountdown(); GM.player.recharges = current_level >= 3 ? 3 : 0; GM.paused = true; playing = true; while (Debris.all_debris.Count > 0) { yield return(null); } playing = false; yield return(new WaitForSeconds(2f)); } run_level++; GM.GameOver(); }