Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawner : MonoBehaviour {
  6.  
  7.     public List<GameObject> Obstacles;
  8.     public Vector3 height;
  9.     public GameObject randomObject;
  10.  
  11.     void Start()
  12.     {
  13.         ChooseRandom();
  14.         StartCoroutine(timer());
  15.     }
  16.  
  17.     void ChooseRandom()
  18.     {
  19.         if (Obstacles.Count != 0)
  20.         {
  21.             randomObject = Obstacles[Random.Range(0, Mathf.RoundToInt(Obstacles.Count - 1))];
  22.         }
  23.     }
  24.  
  25.     void RandomHeight()
  26.     {
  27.         height = new Vector3(gameObject.transform.position.x, Random.Range(0, 2));
  28.     }
  29.  
  30.     IEnumerator timer()
  31.     {
  32.         ChooseRandom();
  33.         RandomHeight();
  34.         Instantiate(randomObject, height, Quaternion.identity);
  35.         yield return new WaitForSeconds(3);
  36.         StartCoroutine(timer());
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement