private void PopulatePool(int size, GameObject gameObject)
 {
     pooledItems = new Stack <GameObject>();
     for (int i = 0; i < size; ++i)
     {
         GameObject go         = GameObject.Instantiate(gameObject);
         PooledItem pooledItem = go.AddComponent <PooledItem>();
         pooledItem.SetPool(this);
         go.SetActive(false);
         pooledItems.Push(go);
     }
 }
        public GameObject InstantiateFromPool(Vector3 postion)
        {
            GameObject next = null;

            if (pooledItems.Count > 0)
            {
                next = pooledItems.Pop();
                next.transform.position = postion;
                next.SetActive(true);
                return(next);
            }

            if (!shouldAutoResize)
            {
                return(null);
            }
            next = GameObject.Instantiate(prefab, postion, Quaternion.identity);
            PooledItem item = next.AddComponent <PooledItem>();

            item.SetPool(this);
            return(next);
        }