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 ChutesSpawner : MonoBehaviour {
- public GameObject objectSpawn; //The object that will be spawned (NOTE: TURN INTO ARRAY LATER FOR MULTIPLE OBJECTS)
- public GameObject[] objectLocation; // the array of locations where object will be spawned
- public float spawnWait; //wait time for numerator to return function
- public int startWait; //time that object has to wait before it does initial sapwn
- public float spawnLeastWait; //smallest wait time between each spawn
- public float spawnMostWait; //longest wait time to spawn object
- public bool stop; //condition to stop the spawning loop
- // int randObject; //for setting amount of random objects spawning
- int randomChute; //for selecting random chute to spawn objects
- // Use this for initialization
- void Start () {
- StartCoroutine(spawner()); //Starts coroutine that makes the spawn system work
- }
- // Update is called once per frame
- void Update () {
- spawnWait = Random.Range(spawnLeastWait, spawnMostWait); //randomly spawns object between least and most wait.
- }
- IEnumerator spawner()
- {
- while (!stop)
- {
- // randObject = Random.Range(0, 2); //Selects objects in array between the 2 values set.
- randomChute = Random.Range(0, 6); //Selects random chute between 1 of the 6 chutes.
- Instantiate(objectSpawn, objectLocation[randomChute].transform.position, transform.rotation);
- yield return new WaitForSeconds(spawnWait);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement