Set to delay firing

So far I have this but can’t seem to get the yield to work on firing. At the moment the player can just spam the space bar.

#pragma strict

//sets width of GuiTexture
var fullWidth : float = 256;
var choosing : boolean = false;
// set what I am firing
var ball : Rigidbody;
//sets where to fire from
var spawnPos : Transform;

// force f bullet
var shotForce : float = 5;
private var thePower : float;
 
function Update () {
 
// fires on shoot
 if(Input.GetButtonUp("Jump")){
  Shoot(thePower);
 }
 
 if(!choosing){
  
  thePower = Mathf.PingPong(Time.time, 1) * fullWidth;
 

  guiTexture.pixelInset.width = thePower;
 }
}
 

function Shoot(power : float){

 choosing = true;
 

 var pFab : Rigidbody = Instantiate(ball, spawnPos.position, spawnPos.rotation);
 

 var fwd : Vector3 = spawnPos.forward;
 pFab.AddForce(fwd * power*shotForce);
 

 yield WaitForSeconds(2);
 
 
 choosing = false;
}

WaitForSeconds doesn’t really work like that. By mashing spacebar, you are calling the function multiple times, and the waiting is done in each function separately. You should instead use a rate of fire timer:

var fireDelay:float=0.5;
@HideInInspector
var firePointer:float=0;

function Shoot(){
   if(Time.timeSinceLevelLoad<firePointer){
      firePointer=Time.timeSinceLevelLoad+fireDelay;
      //do firing things here
   }
}