so i am making an endless runner game. i have my player running and i can instantiate my coins anywhere up ahead my player through the update function but the problem is that since its in update function it keeps spawning them right after one another. what i want is to spawn a bunch of coins lets say 5-6 at once and then wait for some time lets say 20 seconds before spawning them again.
What you need is a coroutine, which allows you to pause code execution. This should work:
void Start()
{
StartCoroutine(InstantiateCoins());
}
IEnumerator InstantiateCoins()
{
//first, instantiate coins
//then wait 20 seconds
yield return new WaitForSeconds(20);
//then call the method again
StartCoroutine(InstantiateCoins());
}