Wait Time Before Be Able To Shoot?

So i have a script that reduces ammo and readds ammo, but i want so it takes some time after u have shooted to be able to shoot again and my script doesnt work? (ShotScar, ReloadScar is my animations)
Please Help!

~carlqwe
Code (js):

#pragma strict

var ammo : float;

function Start () 
{
	ammo = 30;
}

function Update () 
{
	if(Input.GetKeyDown(KeyCode.R))
	{
		if(ammo < 30)
		{
			SendMessage("ReloadScar", SendMessageOptions.DontRequireReceiver);
			ammo = 30;
		}
	}
	
	if(Input.GetMouseButtonDown(0))
	{	
		if(ammo > 0)
		{	
			SendMessage("ShotScar", SendMessageOptions.DontRequireReceiver);
			ShotSL ();
		}
		
		if(ammo < 0)
		{
			ammo = 0;
		}
	}
	
	if(ammo > 30)
	{
		ammo = 30;
	}
}

function OnGUI ()
{
	GUI.Label(Rect(60,15,25,25),ammo.ToString());
}

function ShotSL ()
{
	ammo--;
	yield WaitForSeconds(2);
}

You should make some canShoot boolean.
Check if it’s true before you shoot, then set it to false when you do, and to true again after some time.

So you could do

var canShoot : bool;
if(canShoot && ammo > 0{
 canShoot = false;
 //shoot code here
}

function ShotSL(){
 ammo--;
 yield WaitForSeconds(2);
 canShoot = true;
}

I think that should work.
Alternatively, you could keep a float with the last shooting time, and do something like

if(Time.time-lastShootTime > 2.0f && ammo > 0){
 lastShootTime = Time.time;
 //rest of shoot code
}