Guest User

Untitled

a guest
Apr 26th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. public class RockSpawner : MonoBehaviour
  2. {
  3.     public float spawnRate = 2;
  4.     private float timer = 0;
  5.     public float heightOffset = 10;
  6.     public GameObject asteroid;
  7.     public GameObject logic;
  8.     public float bossTime = 12;
  9.     public float modSpawnRate = 2;
  10.  
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         spawnAsteroid();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         if (timer < modSpawnRate)
  21.         {
  22.             timer = timer + Time.deltaTime;
  23.         }
  24.         else
  25.         {
  26.             spawnAsteroid();
  27.             timer = 0;
  28.             bossTime = logic.GetComponent<bossTime>();
  29.             modSpawnRate = (spawnRate + Random.Range(0,4) + bossTime);
  30. }
  31.     }
  32.  
  33.     void spawnAsteroid()
  34.     {
  35.         float lowestPoint = transform.position.y - heightOffset;
  36.         float highestPoint = transform.position.y + heightOffset;
  37.  
  38.         Instantiate(asteroid, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
  39.     }
  40. }
Add Comment
Please, Sign In to add comment