I’m trying to make a laser that shoots 3 shots every 3 seconds(but with just a tiny delay between shots). I have got the laser shooting, but I don’t understand how to add the delay to the shot. I tried using a delay method WaitForSeconds but it crashes the game(stuck in an infinite loop somehow?). amnt is preset to 3.
private void fire(int amnt)
{
for(int x = 0; x < amnt; x++)
{
while(!canShoot)
{
//wait until timer goes
}
pos = gun.transform.position;
Instantiate(laser, pos, Quaternion.LookRotation(player.transform.position - pos + new Vector3(0, 1.5f, 0)));
canShoot = false;
StartCoroutine(waitBetweenShots());
}
}
IEnumerator waitBetweenShots()
{
yield return new WaitForSeconds(.1f);
canShoot = true;
}
}