I have code which builds up charge while a button is held down and then I want it to execute a function only once. This is within a function called ScanInput() which is called from Update()
while(Input.GetButton("Fire1"))// && (Time.deltaTime > nextFire))
{
//Add to the charge as long as the
// user is holding the button
chargeLevel += Time.deltaTime * chargeSpeed;
firedMissile = false;
firePlayer001Missile(firedMissile);
yield;
}
chargeLevel = 0.0;
Heres the code for the function firePlayer001Missile
function firePlayer001Missile(firedMissile)
{
if(!firedMissile)
{
var player001Missile = new Instantiate(currentMissileType, GameObject.Find("Player001ShotSpawnPoint001").transform.position,Quaternion.identity);
currentMissileType.transform.Translate(0,shootForce*Time.deltaTime,0);
player001Missile.rigidbody.AddForce(transform.up*shootForce);
bulletCount++;
firedMissile=true;
}
return firedMissile;
}
As it is now, it fires a barrage of bullets which I think is equal to the number of calls to the function firePlayer001Missile; I want it to fire only one bullet after the fire button has been held down.