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

public class ParticlePool : MonoBehaviour {

    List<GameObject> particles;
    public int pooledParticles = 1000;

	// Use this for initialization
	void Start () {
        particles = new List<GameObject>();
        GameObject part =(GameObject) Resources.Load("Particle");
        for (int i = 0; i < pooledParticles; i++) {
            GameObject obj = (GameObject)Instantiate(part);
            obj.SetActive(false);
            particles.Add(obj);
        }
	}
	
	// Update is called once per frame
	void Update () {
	    
	}

    public void Shoot(Vector3 position, Quaternion rotation) {
        for (int i = 0; i < particles.Count; i++) {
            if (!particles[i].activeInHierarchy) {
                particles[i].transform.position = position;
                particles[i].transform.rotation = rotation;
                particles[i].SetActive(true);
                break;
            }
        }
    }
}
