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

public class Pool : MonoBehaviour
{
    static List<PoolableObject> availableObjects = new List<PoolableObject>();
    static GameObject NPCPrefab;

    private void Awake()
    {
        NPCPrefab = (GameObject)Resources.Load("NPC");
    }

    public static void Despawn(PoolableObject poolable)
    {
        //  availableObjects.Add(poolable);
        Destroy(poolable.gameObject);
    }

    public static NPC SpawnNewNPC(NPC.NPCState newState, Vector3 newPosition)
    {
        /*for (int i = 0; i < availableObjects.Count; i++)
        {
            if (availableObjects[i] is NPC)
            {
                NPC npc = (NPC)availableObjects[i] as NPC;
                npc.Spawn(newState, newPosition);
                availableObjects.Remove(npc);
                return npc;
            }
        }*/
        PoolableObject newObject = GameObject.Instantiate(NPCPrefab).GetComponent<PoolableObject>();
        NPC generatedNPC = newObject as NPC;
        generatedNPC.Spawn(newState, newPosition);
        return generatedNPC;
    }
}