using UnityEngine;
using System.Collections;

public class SpawnPoint : MonoBehaviour {
	MobPool pool;
	public float spawn_interval=1f;
	float spawn_timer=0;
	public int max_spawn=20;
	[HideInInspector]
	public int spawn_nb=0;

	HUD hud;
	ExplosionPool expool;

	void Start () {
		pool = GameObject.FindGameObjectWithTag("MobPool").GetComponent<MobPool>();
		//hud = GameObject.FindGameObjectWithTag("HUD").GetComponent<HUD>();
		expool = GameObject.FindGameObjectWithTag("UnitcornExplodPool").GetComponent<ExplosionPool>();
		Debug.Log("expool == null? " + (expool == null ) );
	}
	
	// Update is called once per frame
	void Update () {
		spawn_timer += Time.deltaTime;

		if ( spawn_nb < max_spawn && spawn_timer > spawn_interval ) {
			GameObject g = pool.Get();
			TEST_MobCube cube = g.GetComponent<TEST_MobCube>();
			cube.Spawn();
			cube.hud = hud;
			cube.explosionPool = expool;
			cube.spawnPoint = this;
			spawn_nb ++;
			spawn_timer = 0;
		}
	}
}
