I was wondering how to make a RPM(Rounds per Miniute) style fire rate. I have a fire rate now, but the problem is that the faster the fire rate, the lower the value. So if you want a really fast shooting gun, ‘fireRate’ would be ‘0.1f’. If someone in the game reads a fire rate of ‘0.1’, they will think it is slow when in reality, it is the opposite of what they think. So please explain to me or show some code (or both) on how to implement a RPM style fire rate in my game. So basically, the higher the ‘fireRate’ variable, the faster the gun will shoot. Here is my code by the way:
if (gun.shootMode == Gun.ShootMode.Semi_Automatic)
{
if (Input.GetButtonDown("Fire1") && Time.time > nextShoot)
{
gun.ammo.magazineAmmo--; //Takes away one bullet of ammo
nextShoot = Time.time + gun.fireRate;
Attack(); //Attacks
}
}
else
{
//do other stuff I dont need to show you guys
}
This is in the update loop? You should really think about doing it in a coroutine instead with simple “start routine” and “stop routine” when the button is pressed and let go. That way, you can use “yield new WaitForSeconds(some float)” in a loop instead, which would make this far simpler. In that case, all you do is take the fireRate (let’s say 120 bullets per minute) and divide it by 60 (2 bullets per second) and then divide 1 by that number to get the number of seconds between each shot (.5, in this case). The yield is simply