Power up weapon shot before releasing and resetting power

What would be the code so that holding down a button will charge up shot,then releasing that button fires the charged shot and resets the charge; as used in games like r-type?

I would do something like this. It starts charging when the user clicks the fire button and will release when they let go.

var chargeLevel : float = 0; //Don't change this in the inspector.
var chargeSpeed : float = 1; //Default, the charge will go up 1 per second
var isCharging = false;

function Update () {
     if (Input.GetButtonDown("FireButton")) { //Did the user click?
          if(!isCharging) { //Some what unnecessary due to the way the Input is
          // setup
               isCharging = true;
               CalculateCharge();
          }
     }
}

function CalculateCharge () {
     while(Input.GetButton("FireButton")) { //Add to the charge as long as the
     // user is holding the button
          chargeLevel += Time.deltaTime * chargeSpeed;
          yield; //Will cause a crash without this.
      }

     //Fire Projectile
     // Reset the vars.
     chargeLevel = 0.0;
     isCharging = false;
}