Waiting for fractions of a Second

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;
    }
}

This isn’t going to work because you are starting 3 coroutines in the same frame. Additionally, unless your “wait until timer goes” comment is hiding other code, that while loop will be an infinite loop. Once you get into the while loop, you cannot leave. This is because coroutines are still executed on the main thread, just possibly at a later time. You cannot have a coroutine running simultaneously with your other code (well, you can, but there are a ton of limitations and generally it’s not done). What you want is something like this:

private void fire(int amount) {
	StartCoroutine(FireShots(amount));
}

private IEnumerator FireShots(int num){
	for (int i = 0; i < num; i++){
		pos = gun.transform.position;
		Instantiate(laser, pos, Quaternion.LookRotation(player.transform.position - pos + new Vector3(0, 1.5f, 0)));
		yield return new WaitForSeconds(.1f);
	}
}