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;
}