IEnumerator delayDie(float deathLength) { // waits before destroying the object yield return(new WaitForSeconds(deathLength)); if (!isSpecialLevel) { spawnController.spawnCount--; if (Random.Range(0, 2) == 0) { Instantiate(orb, gameObject.transform.position, gameObject.transform.rotation); } else if (Random.Range(0, 9) == 0) { // 1/15 chance enemy spawns a player powerup PowerupController powerupControl = GameObject.FindGameObjectWithTag("PowerupController").GetComponent <PowerupController>(); powerupControl.spawnRandomPowerup(gameObject.transform.position, gameObject.transform.rotation); } spawnController.OnDeathSpawn(); } Destroy(gameObject); }