using System.Collections;
using UnityEngine;
public class PrefabSpawner : MonoBehaviour
{
public GameObject prefabs;
public Vector3 spawnValues;
public float spawnWait;
public float spawnMostWait;
public float spawnLeastWait;
public int startWait;
public bool stop;
int randPrefab;
void Start()
{
StartCoroutine(waitSpawner());
}
void Update()
{
spawnWait = Random.Range(spawnLeastWait, spawnMostWait);
}
IEnumerator waitSpawner()
{
yield return new WaitForSeconds (startWait);
while (!stop)
{
randPrefab = Random.Range(0, 9);
Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), 1, Random.Range(-spawnValues.z, spawnValues.z));
Instantiate(prefabs[randPrefab], spawnPosition + transform.TransformPoint(0, 0, 0), Random.rotation);
yield return new WaitForSeconds(spawnWait);
}
}
}