public GameObject Pool (GameObject thing, float delay) {
StartCoroutine(PoolDelayed(thing, delay, 0));
return thing;
}
IEnumerator PoolDelayed (GameObject thing, float delay, int dummy) {
Debug.Log ("PoolDelayed is called.");
yield return new WaitForSeconds (delay);
Pool (thing);
}
Debug.Log (as well as the actual game) reveals that instead of waiting for delay
then proceeding, the whole coroutine is repeated every frame for the whole duration of delay
.
I’ve actually heard of some amount of wonkiness regarding everything around yield, but this is the first time I ever have WaitForSeconds()
do that in all the times I’ve been using it. Has somebody got some context to it and/or maybe a solution?