Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator<float> SpawnBullets() //coroutine used for spawning the bullets
- {
- while (true)
- {
- CheckForStarsCooldown(indexToStartSpawningFrom);
- CalculateSpawnChance(indexToStartSpawningFrom);
- }
- }
- private void CheckForStarsCooldown(int indexToStartSpawningFrom)
- {
- for(int i = indexToStartSpawningFrom; i < StarBullets.Count; i++)
- {
- if(!StarBullets[i].GetComponent<BaseBullet>().canBeSpawned)
- {
- StarBullets[i].GetComponent<BaseBullet>().coolDownToSpawn -= Time.deltaTime;
- if(StarBullets[i].GetComponent<BaseBullet>().coolDownToSpawn <= 0)
- {
- StarBullets[i].GetComponent<BaseBullet>().canBeSpawned = true;
- }
- }
- }
- }
- private void CalculateSpawnChance(int indexToStartFrom)
- {
- //..Calculate chance
- for (int i = indexToStartFrom; i < StarBullets.Count; i++)
- {
- if (StarBullets[i].GetComponent<BaseBullet>().canBeSpawned && randomChance < currentChance)
- {
- theStarBullet = Instantiate(StarBullets[i]) as GameObject;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement