public GameObject GetPooledObject(GameObject poolObject) { string objectName = poolObject.name; if (!objectPools.ContainsKey(objectName)) { InitializePool(poolObject, 20, objectName); } Pool pool = objectPools[objectName]; List <GameObject> objectPool = pool.objectPool; for (int i = 0; i < objectPool.Count; i++) { if (!objectPool[i].activeInHierarchy) { return(objectPool[i]); } } if (pool.willGrow) { GameObject obj = Instantiate(pool.objectType); obj.SetActive(false); objectPool.Add(obj); return(obj); } return(null); }