Advertisement
Guest User

Untitled

a guest
May 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public GameObject topSpawn, leftSpawn, rightSpawn, bottomSpawn;
  2. public GameObject spawnLocation;
  3. public float lastSpawn;
  4. public float timeBetweenSpawns = 1f;
  5. public float timeSinceLastSpawnShuffle;
  6.  
  7.  
  8. void Awake()
  9. {
  10. GetSpawnLocation();
  11. }
  12.  
  13. void Update()
  14. {
  15. lastSpawn = lastSpawn + Time.deltaTime;
  16. timeSinceLastSpawnShuffle = timeSinceLastSpawnShuffle + Time.deltaTime;
  17. if (timeSinceLastSpawnShuffle > 10f)
  18. {
  19. GetSpawnLocation();
  20. }
  21. }
  22.  
  23. public void GetSpawnLocation()
  24. {
  25. float spawnLocationChance = Random.value;
  26.  
  27. if (spawnLocationChance >= 0 && spawnLocationChance < 0.25)
  28. {
  29. spawnLocation = topSpawn;
  30. }
  31. if (spawnLocationChance >= 0.25 && spawnLocationChance < 0.50)
  32. {
  33. spawnLocation = rightSpawn;
  34. }
  35. if (spawnLocationChance >= 0.50 && spawnLocationChance < 0.75)
  36. {
  37. spawnLocation = bottomSpawn;
  38. }
  39. if (spawnLocationChance >= 0.75 && spawnLocationChance < 1.00)
  40. {
  41. spawnLocation = leftSpawn;
  42. }
  43. }
  44.  
  45. void SpawnEnemies()
  46. {
  47. if (lastSpawn > timeBetweenSpawns && enemiesSpawned < enemiesToSpawn)
  48. {
  49. if (spawnLocation == topSpawn || spawnLocation == bottomSpawn)
  50. {
  51. GameObject enemy = Instantiate (enemy, (spawnLocation.transform.position + new Vector3 (Random.Range(-20, 20), 0, 0)), Quaternion.identity) as GameObject;
  52. lastSpawn = 0;
  53. }
  54.  
  55. if (spawnLocation == leftSpawn || spawnLocation == rightSpawn)
  56. {
  57. GameObject enemy = Instantiate (enemy, (spawnLocation.transform.position + new Vector3 (0, 0, Random.Range(-20, 20))), Quaternion.identity) as GameObject;
  58. lastSpawn = 0;
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement