using UnityEngine;
using System.Collections;

public class ParticleSpawner : MonoBehaviour {
    public float Interval=5;
    public Vector3 Area;
    public GameObject[] Prefabs;

    float timer = 0;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        timer += Time.deltaTime;
        if (timer>Interval)
        {
            timer = 0;
            var Adjust = Area*Random.value;
            var position = transform.position - Area/2 + Adjust;
            var obj = Instantiate(Choose(Prefabs), position, Quaternion.identity) as GameObject;
            obj.transform.parent = transform;
        }
	}

    private GameObject Choose(GameObject[] Prefabs)
    {
        float rand = Random.value * (Prefabs.Length+1) - 1;
        return Prefabs[(int)rand];
    }
    
    void OnDrawGizmos()
    {
        Gizmos.DrawWireCube(transform.position,new Vector3(Area.x, Area.y, 0));
    }
}
