- Home /
Question by
JohnFreeman · Jan 15 at 01:01 AM ·
c#waitforsecondsnoobfireno error
Issue inturrupting waitforseconds with timescale 0
I apologize ahead of time if i cant describe this well, there's no actual errors to go off of which complicates things
I'm using coroutines to have a delay between shots using instantiate. The issue is pausing using Time.timeScale 0, my only guess WaitForSeconds is ignoring the sudden change in scale. The result is, if the player pauses and unpauses rapidly, it effectively doubles, triples, etc their firerate. Im assuming its an issue with my usage of waitforseconds since I have a bool to stop the loop until WFS is over.
here's a pared down script but I can prove more if needed
if (Input.GetButton("Fire1") && canShoot == true)
{
Instantiate(ammoType, shotSpawn.position, shotSpawn.rotation);
canShoot = false;
StartCoroutine(Shoot());
}
IEnumerator Shoot()
{
yield return new WaitForSeconds(shotDelay / fireRateMulti);
canShoot = true;
// should not instantiate if canShoot = false
// should not instantiate until after waitforseconds is over
}
.
swggdbm.png
(19.8 kB)
xrw0ver.png
(20.4 kB)
Comment