Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Test : MonoBehaviour {
- public GameObject meteor;
- //We can use this vector 2 to set min/max on time between meteors so they are somewhat randomiszed.
- public Vector2 meteorWaitPeroid;
- // Start is called before the first frame update
- / Start is called before the first frame update
- void Start()
- {
- //Call the coroutine once at start
- StartCoroutine(Spawnmeteor());
- }
- // Update is called once per frame
- IEnumerator Spawnmeteor()
- {
- //Wait a randomized amount of time
- yield return new WaitForSeconds (Random.Range (meteorWaitPeroid.x, meteorWaitPeroid.y);
- Vector3 randomSpawnPosition = new Vector3(Random.Range(-10f, 10), 0, Random.Range (-10f,10f));
- Vector3 randomSpawnRotation = Vector3.up * Random.Range(0, 360);
- Instantiate (meteor, randomSpawnPosition, Quaternion.Euler(randomSpawnRotation));
- //Recursively call the coroutine
- //as your script progresses you might want a bool around this to stop recalls of spawning
- //in the event the meteors have stopped or disable the script itself.
- StartCoroutine(Spawnmeteor());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement