IEnumerator GenerateTrashDebris(int level) { List <Debris> trash = new List <Debris>(); if (trash.Count > 0) { throw new UnityException("Trash was not empty"); } Debris.trash = new List <Debris>(); for (int i = 0; i < trash_debris_num[level]; i++) { Debris d = Instantiate(debris_prefab); d.persistent = false; trash.Add(d); } Debris.trash.AddRange(trash); foreach (Debris d in trash) { d.Initialize(); yield return(new WaitForSeconds(generate_delay[level] / 2f));; d.Fly(); } trash_routine = null; }