- Home /
Spawner does'nt spawn smootlhy
Hi guys, I've build a small game who spawns a prefab using objectpooling, it works pretty good but i've a problem and i don't undersatnd why my coroutine is acting so. The spawn is not smooth appear like i'm spawning waves but i want to spawn continously. Here's my code if someone have an idea. Thanks in advance
IEnumerator Spawn()
{
while (true)
{
//yield return new WaitForSeconds(spawnWait);
//Getting random position of spawn on X axis
spawnPosition = transform.position;
spawnPosition.x = Random.Range(520f , 370f);
//Get a Fish with another method
GameObject fishSpawned = GetFish();
//if Get fish returned a GO, then active it and spawn it at spawn pos
if (fishSpawned != null)
{
fishSpawned.transform.position = spawnPosition;
fishSpawned.SetActive(true);
}
yield return new WaitForSeconds(spawnWait);
}
}
What do you mean by spawning smoothly? Do you have a problem with the X coordinates being random and not wave-like, or do you have a problem with the wait interval?
The problem is with the wait intervall, sometimes it mlakes some pause during spawning (ex : 3-4 spawn then a blank and then again 3-4 spawn)
Are you sure that the object pool is not empty when trying to spawn a fish? If that is the case, then you have to use a bigger pool, or make sure that the used fishes get back to the pool for reusing. You could post the object pool and the scripts which use that pool, if you are still not sure where the problem is.