public void Despawn(PooledObjectType tag, GameObject objToDespawn) { PoolDictionary[tag.ToString()].Enqueue(objToDespawn); objToDespawn.SetActive(false); objToDespawn.transform.position = Vector3.zero; IPooledObject iPooledObj = objToDespawn.GetComponent <IPooledObject>(); if (iPooledObj != null) { iPooledObj.OnObjectDespawn(); } }
public GameObject SpawnFromPool(PooledObjectType tag, Vector3 pos, Quaternion rot) { if (!PoolDictionary.ContainsKey(tag.ToString())) { Debug.LogWarning("PoolObjects with Tag " + tag + " doesn't exist .."); return(null); } GameObject objToSpawn = PoolDictionary[tag.ToString()].Dequeue(); objToSpawn.SetActive(true); objToSpawn.transform.position = pos; objToSpawn.transform.rotation = rot; IPooledObject iPooledObj = objToSpawn.GetComponent <IPooledObject>(); if (iPooledObj != null) { iPooledObj.OnObjectSpawn(); } PoolDictionary[tag.ToString()].Enqueue(objToSpawn); return(objToSpawn); }