In the objectsToPool array there are 3 gameobjects. When the for loop runs it chooses one of the three gameobjects. This chosen gameobject populates the entire pool (20 in this case). What I am looking to do is randomize this. Have the pool (20) consist of a mixture of the objectsToPool array. I am not sure how I should modify the for loop to accomplish this.
public class B_ObjectPooler : MonoBehaviour
{
public static B_ObjectPooler SharedInstance;
public List<GameObject> pooledObjects;
//public GameObject objectToPool;
public GameObject[] objectsToPool;
public int amountToPool;
private void Awake()
{
SharedInstance = this;
}
// Start is called before the first frame update
void Start()
{
int randomNumber = Random.Range(0, objectsToPool.Length);
pooledObjects = new List<GameObject>();
GameObject tmp;
for(int i = 0; i < amountToPool; i++)
{
//tmp = Instantiate(objectToPool);
tmp = Instantiate(objectsToPool[randomNumber]);
tmp.SetActive(false);
pooledObjects.Add(tmp);
}
}
public GameObject GetPooledObject()
{
for(int i = 0; i < amountToPool; i++)
{
if(!pooledObjects[i].activeInHierarchy)
{
return pooledObjects[i];
}
}
return null;
}
}