EDIT: Count() is actually the amount of deactivated objects. Not active objects.
Thanks here for the developers who wrote this code.
Hi,
I found this ObjectPool Code.
Website: http://unitypatterns.com/resource/objectpool/
Github ObjectPool Script: https://github.com/UnityPatterns/ObjectPool/blob/master/Assets/ObjectPool/Scripts/ObjectPool.cs
When I try this:
Debug.Log(ObjectPool.Count(cube));
I don’t get a number. It’s always zero.
My code:
// a prefab cube in prefab folder
public Transform cube;
void Start () {
ObjectPool.CreatePool(cube);
StartCoroutine (Cubes ());
}
IEnumerator Cubes ()
{
while (true)
{
for (int i = 0; i < 10; i++)
{
Quaternion spawnRot = Quaternion.identity;
ObjectPool.Spawn(cube, spawnPos.position, spawnRot);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
}
}
void Update () {
Debug.Log (ObjectPool.Count(cube));
}
In the console I see only 0 (zero).
Has somebody an idea why?
Thanks.