using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MonsterSpawner : MonoBehaviour {

    public GameObject monsterPrefab;

    public float spawnInterval = 10f;
    public float timeSinceSpawn = 0;

    public float spawnDistance = 10f;

    public List<Monster> monsters = new List<Monster>();

	// Use this for initialization
	void Start () {
        
	}
	
	// Update is called once per frame
	void Update () {
        timeSinceSpawn += Time.deltaTime;

        if (timeSinceSpawn > spawnInterval)
        {
            int angle = Random.Range(0, 360);

            Vector3 offset = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0);
            offset.Normalize();
            offset *= spawnDistance;

            Vector3 spawnLoc = transform.position + offset;


            GameObject monster = (GameObject)GameObject.Instantiate(monsterPrefab, spawnLoc, new Quaternion());

            monster.transform.parent = transform;
            monster.GetComponent<Monster>().spawner = this;

            monsters.Add(monster.GetComponent<Monster>());

            timeSinceSpawn = 0;
        }
	}
}
