Hi all!
I am trying to spawn a GameObject every five seconds. I use WaitForSeconds to do this. However, my GameObject is spawned every frame instead. Where is the flaw in my code? Thanks!
You can try that
bool canInstantiate = true
void Start()
{
enemy = ...;
if (canInstantiate)
StartCoroutine(EnemySpawn());
}
IEnumerator EnemySpawn()
{
canInstantiate = false;
Instantiate(......;
yield return new WaitForSeconds(5f);
canInstantiate = true;
}