IEnumerator DoFancyRaindrops() { doingArtisticRaindrops = true; rainPlayer.Play(); while (doingArtisticRaindrops) { GameObject go = SimplePool.Spawn(artsyRaindropObject, new Vector3(Random.Range((playerCS.starting_X - playerCS.boundary_X), (playerCS.starting_X + playerCS.boundary_X)), 6, 0), Quaternion.identity); float factor = Random.Range(0.5f, 2.5f); go.transform.localScale = new Vector3(0.06f, 0.06f, 1.0f) * factor; Raindrop rdcs = go.GetComponent <Raindrop>(); rdcs.Setup(); rdcs.speed = Random.Range(7.0f, 15.0f); yield return(new WaitForSeconds(Random.Range(0.01f, 0.05f))); } yield return(null); }
IEnumerator SpawnRaindrops() { /// Instead of calling Instantiate(), use this: /// SimplePool.Spawn(somePrefab, somePosition, someRotation); /// /// Instead of destroying an object, use this: /// SimplePool.Despawn(myGameObject); /// /// If desired, you can preload the pool with a number of instances: /// SimplePool.Preload(somePrefab, 20); while (dropsCollected < dropsToCatch) { if (Paused) { yield return(new WaitForSeconds(0.5f)); continue; } //GameObject go = GameObject.Instantiate(raindropObject); float newX; if (dropsCollected == 0) { newX = Random.Range((playerCS.starting_X - playerCS.boundary_X), (playerCS.starting_X + playerCS.boundary_X)); lastSpawnedDropPosition = new Vector3(newX, 6, 0); } else { newX = Random.Range(Mathf.Max((lastSpawnedDropPosition.x - currentLevelSet[currentLevel].maxHorizDistanceBetweenDrops), (playerCS.starting_X - playerCS.boundary_X)), Mathf.Min((lastSpawnedDropPosition.x + currentLevelSet[currentLevel].maxHorizDistanceBetweenDrops), (playerCS.starting_X + playerCS.boundary_X))); } GameObject go = SimplePool.Spawn(raindropObject, new Vector3(newX, 6, 0), Quaternion.identity); Raindrop rdcs = go.GetComponent <Raindrop>(); rdcs.Setup(); rdcs.speed = Random.Range(currentLevelSet[currentLevel].minDropSpeed, currentLevelSet[currentLevel].maxDropSpeed) * currentDiff.masterSpeed; lastSpawnedDropPosition = go.transform.position; yield return(new WaitForSeconds(Random.Range(currentLevelSet[currentLevel].minTimeBetweenDrops, currentLevelSet[currentLevel].maxTimeBetweenDrops))); } yield return(null); }