Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. IEnumerator<float> SpawnBullets() //coroutine used for spawning the bullets
  3. {
  4. while (true)
  5. {
  6. CheckForStarsCooldown(indexToStartSpawningFrom);
  7. CalculateSpawnChance(indexToStartSpawningFrom);
  8. }
  9. }
  10.  
  11. private void CheckForStarsCooldown(int indexToStartSpawningFrom)
  12. {
  13. for(int i = indexToStartSpawningFrom; i < StarBullets.Count; i++)
  14. {
  15. if(!StarBullets[i].GetComponent<BaseBullet>().canBeSpawned)
  16. {
  17. StarBullets[i].GetComponent<BaseBullet>().coolDownToSpawn -= Time.deltaTime;
  18. if(StarBullets[i].GetComponent<BaseBullet>().coolDownToSpawn <= 0)
  19. {
  20. StarBullets[i].GetComponent<BaseBullet>().canBeSpawned = true;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. private void CalculateSpawnChance(int indexToStartFrom)
  27. {
  28. //..Calculate chance
  29. for (int i = indexToStartFrom; i < StarBullets.Count; i++)
  30. {
  31. if (StarBullets[i].GetComponent<BaseBullet>().canBeSpawned && randomChance < currentChance)
  32. {
  33. theStarBullet = Instantiate(StarBullets[i]) as GameObject;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement