using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {

    public float Width;
    public float SpawnTimeMin;
    public float SpawnTimeMax;
    public GameObject[] objects;
    public Transform others;

    public void startSpawning()
    {
        StartCoroutine(waitAndAdd());
    }
    IEnumerator waitAndAdd()
    {
        yield return new WaitForSeconds(Random.Range(SpawnTimeMin, SpawnTimeMax));
        Instantiate(objects[Random.Range(0, objects.Length)], new Vector3(Random.Range(-Width, Width), transform.position.y, transform.position.z), Quaternion.Euler(0, 180, 0),
            others);
        StartCoroutine(waitAndAdd());
    }
}
