SHARE
TWEET

Untitled

a guest Feb 14th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using UnityEngine;
  6.  
  7.  
  8.  
  9. public class Test : MonoBehaviour {
  10.  
  11.  
  12.     public GameObject meteor;
  13.     //We can use this vector 2 to set min/max on time between meteors so they are somewhat randomiszed.
  14.     public Vector2 meteorWaitPeroid;
  15.  
  16.     // Start is called before the first frame update
  17.  
  18.     / Start is called before the first frame update
  19.  
  20.     void Start()
  21.  
  22.     {
  23.         //Call the coroutine once at start
  24.         StartCoroutine(Spawnmeteor());
  25.     }
  26.  
  27.  
  28.  
  29.     // Update is called once per frame
  30.  
  31.     IEnumerator Spawnmeteor()
  32.  
  33.     {
  34.         //Wait a randomized amount of time
  35.         yield return new WaitForSeconds (Random.Range (meteorWaitPeroid.x, meteorWaitPeroid.y);
  36.         Vector3 randomSpawnPosition = new Vector3(Random.Range(-10f, 10), 0, Random.Range (-10f,10f));
  37.         Vector3 randomSpawnRotation = Vector3.up * Random.Range(0, 360);
  38.         Instantiate (meteor, randomSpawnPosition, Quaternion.Euler(randomSpawnRotation));
  39.         //Recursively call the coroutine
  40.         //as your script progresses you might want a bool around this to stop recalls of spawning
  41.         //in the event the meteors have stopped or disable the script itself.
  42.         StartCoroutine(Spawnmeteor());
  43.     }
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top