using UnityEngine;
using System.Collections.Generic;

public class ExplosionPool : MonoBehaviour
{
	[Range(4,32)]
	public int initCapacity=4;
	public string registerName;

	public ParticleSystem explosion;
	List<GameObject> list;
	
	void Awake () {
		list = new List<GameObject>(initCapacity);
		for(int i=0; i<initCapacity; i++ ){
			GameObject k = ( GameObject) Instantiate(explosion.gameObject);
			k.transform.parent = transform;
			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(explosion.gameObject);
		k.transform.parent = transform;
		list.Add(k);
		return k;
	}
}

