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 Spawner : MonoBehaviour {
- public List<GameObject> Obstacles;
- public Vector3 height;
- public GameObject randomObject;
- void Start()
- {
- ChooseRandom();
- StartCoroutine(timer());
- }
- void ChooseRandom()
- {
- if (Obstacles.Count != 0)
- {
- randomObject = Obstacles[Random.Range(0, Mathf.RoundToInt(Obstacles.Count - 1))];
- }
- }
- void RandomHeight()
- {
- height = new Vector3(gameObject.transform.position.x, Random.Range(0, 2));
- }
- IEnumerator timer()
- {
- ChooseRandom();
- RandomHeight();
- Instantiate(randomObject, height, Quaternion.identity);
- yield return new WaitForSeconds(3);
- StartCoroutine(timer());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement