using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectPool : MonoBehaviour { public static ObjectPool instance; public static Dictionary> pool; void Awake(){ instance= this; } public static GameObject Spawn(GameObject obj, Vector3 position){ if(pool.ContainsKey(obj)){ //use from pool if(pool[obj].Count <=0){ GameObject go = Instantiate(obj, position, Quaternion.identity); pool.Add(obj, new List()); pool[obj].Add(go.transform); return go; }else{ GameObject chosen = pool[obj][0].gameObject; pool[obj].RemoveAt(0); return chosen; } }else{ GameObject go = Instantiate(obj, position, Quaternion.identity); pool.Add(obj, new List()); pool[obj].Add(go.transform); return go; } } public static void Despawn(GameObject obj){ // if() } } public class PoolItems{ }