Shoot Rate Script Problems

hey all
So I’m still fairly new to this and have been doing tutorials but am now trying to be a bit more independent and just write things naturally
basically I’m just trying to set a cooldown on an ability (which you right click to use)
this is the loop I’m using to accomplish that (obviously unsuccessfully haha)

	public float ShootRate = 10.0f;
	private float LastShootTime = 1.0f;

	void Update () {
		if(Input.GetKeyUp(KeyCode.Mouse1)){
			if((Time.time - LastShootTime) >= ShootRate){
				fire ();
				LastShootTime = Time.time;
			}
			
	
	      }
}

Thanks for the help
Cheers!

There’s nothing wrong with the code. What problem are you having?

It doesn’t seem to limit how often I can cast the ability in any sense. I have the script applied to the player, but it doesn’t seem to do anything

Also, is there a better way to test than the play button? Everytime I click the mouse buttons it clicks the editor and pauses…

Okay I got it to work. Just closed and reopened Unity. Not sure why that worked haha
But also in regards for testing, is there a better option that doesn’t allow you to click into the console? I have a script that hides the cursor but it still lets me click out of it.