Advertisement
Guest User

ChutesSpawner123123131

a guest
Feb 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ChutesSpawner : MonoBehaviour {
  6.     public GameObject objectSpawn;      //The object that will be spawned (NOTE: TURN INTO ARRAY LATER FOR MULTIPLE OBJECTS)
  7.     public GameObject[] objectLocation;     // the array of locations where object will be spawned
  8.  
  9.     public float spawnWait;     //wait time for numerator to return function
  10.     public int startWait;       //time that object has to wait before it does initial sapwn
  11.     public float spawnLeastWait;        //smallest wait time between each spawn
  12.     public float spawnMostWait;     //longest wait time to spawn object
  13.  
  14.     public bool stop;       //condition to stop the spawning loop
  15.   //  int randObject;      //for setting amount of random objects spawning
  16.     int randomChute;       //for selecting random chute to spawn objects
  17.  
  18.     // Use this for initialization
  19.     void Start () {
  20.         StartCoroutine(spawner());      //Starts coroutine that makes the spawn system work
  21.     }
  22.    
  23.     // Update is called once per frame
  24.     void Update () {
  25.         spawnWait = Random.Range(spawnLeastWait, spawnMostWait);        //randomly spawns object between least and most wait.
  26.     }
  27.  
  28.     IEnumerator spawner()
  29.     {
  30.         while (!stop)
  31.         {
  32.         //    randObject = Random.Range(0, 2);       //Selects objects in array between the 2 values set.
  33.             randomChute = Random.Range(0, 6); //Selects random chute between 1 of the 6 chutes.
  34.             Instantiate(objectSpawn, objectLocation[randomChute].transform.position, transform.rotation);
  35.  
  36.             yield return new WaitForSeconds(spawnWait);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement