Controlling fire rate with C#

I’m trying to controller the player’s weapon’s fire rate with nextFire = Time.time + fireRate;, but right now this line of code doesn’t seem to work. Plz help.

We cannot help you like this, we need more information.

1 Like

We can’t really help with just that small bit of code.

But here is an example for cooldown

private float fireRate = 10.0f;
private float nextFire = -1f;

void Update()
{
    if(nextFire > 0)
    {
        nextFire -= Time.deltaTime;
        return;
        //can not fire
    }else
    {
        //can fire
    }
}

void WeaponWasFired()
{
    nextFire = fireRate;  //10 sec until next fire is available
}