using UnityEngine;
using System.Collections.Generic;

public class MobPool : MonoBehaviour {
	
	[Range(4,32)]
	public int initCapacity=4;
	
	public GameObject mob;
	List<GameObject> list;
	Transform root;
	HUD hud;

	void Awake () {
		root = new GameObject("mob_pool").transform;
		list = new List<GameObject>(initCapacity);
		for(int i=0; i<initCapacity; i++ ){
			GameObject k = ( GameObject) Instantiate(mob);
			k.transform.parent = root;
			k.SetActive(false);
			list.Add(k);
		}
	}
	
	public GameObject Get() {
		foreach (GameObject g in list ) {
			if ( !g.activeInHierarchy ) {
				g.SetActive(true);
				return g;
			}
		}
		GameObject k = ( GameObject) Instantiate(mob);
		k.transform.parent = root;
		list.Add(k);
		return k;
	}

}
