Object Pooling Help

I’ve just started creating a Object Pooler for my game to be able to recycle multiple things such as explosion effects and enemies. I followed a tutorial online, this one: - YouTube and ended up with this script:

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

public class ObjectPooler : MonoBehaviour {

	public static ObjectPooler current;

	public GameObject pooledObject;
	public int pooledAmount;

	List<GameObject> pooledObjects;

	void Start()
	{
		pooledObjects = new List<GameObject>();
        for(int i = 0; i < pooledAmount; i++)
        {
		    GameObject obj = (GameObject)Instantiate(pooledObject);
            pooledObjects.Add(obj);
            obj.SetActive(false);
        }
	}

	public GameObject InstantiatePooledObject()
	{
		for(int i = 0; i < pooledObjects.Count; i++)
		{
			if(!pooledObjects*.activeInHierarchy)*
  •  	{*
    

_ return pooledObjects*;_
_
}_
_
}_
_
GameObject obj = Instantiate(pooledObject) as GameObject;_
_
obj.SetActive(false);_
_
pooledObjects.Add(obj);_
_
return obj;_
_
}*_

* public void DestroyPooledObject(GameObject obj, float time)*
* {*
* StartCoroutine(DestoyingPooledObject(obj, time));*
* }*

* IEnumerator DestoyingPooledObject(GameObject obj, float time)*
* {*
* yield return new WaitForSeconds(time);*
* pooledObjects.Add(obj);*
* obj.SetActive(false);*
* yield break;*
* }*
}
I did change a couple of things to suit my needs including adding a method that will disable a pooled object after a certain amount of time. Then I simply attached it to a empty GameObject and filled in the empty variables. This Object Pooler works fine but the main big problem with it is that it only pools one object and when I want to use the Object Pooler for enemies, it won’t work the way it is since I’m already using it for explosion effects.
I was wondering if someone could help me get this working for multiple GameObjects? I can’t really think of a way to do it. And sorry if this is an amateur question.

Hey,

What you did is just fine and you can use it for your requirement as below.

Use this script multiple times for multiple objects like enemy and explosion effect. Further you can not use Singleton (instance named current). You can reference all of them at another manager class and by using references from that you can access all pools.

Ex.

Lets Make gameobjects named EnemyPool and ExplosionPool and assign this script with respected values to each of them. Now you can access EnemyPool using GameObject.Find("EnemyPool").GetComponent<ObjectPooler>() and
ExplosionPool using GameObject.Find("ExplosionPool").GetComponent<ObjectPooler>()

I hope this will help you, and free to ask further help you need.