Pause Animation??? Need Script Help:)

Hey everyone:). So I have an animation that flickers the light of my flashlight, and this animation plays when energy<600. The energy for example stops decreasing if i turn the flashlight off, but my animation (that represents with this “flickers” the end of the light) keeps playing when the light is off, so the animation ends before the energy is out… The script is almost ready, everything is working at this moment except my idea of pausing the animation, could enyone fix my script so the animation gets paused when the light is off??(this action is done by presing “f” key)
The Script:

var lightSource : Light; //Connect the light source in the Inspector
var shootSound:AudioClip;
var animationComp : Animation;//Ojo: (3000 = 5 min, Animacion dura 60 seg,  
                                 //asi que esta en ultimo 5to de los 5 min(energy<600))
 
static var energy : float = 3000; //The energy amount of the flashlight, 
static var turnedOn : boolean = false; //Boolean to check whether it's turned on or off
private var drainSpeed : float = 10.0; //The speed that the energy is drained
 lightSource.enabled = false; 
function Update () {
    if (Input.GetKeyDown(KeyCode.F)) ToggleFlashlight();
 
}
 
//When the player press F we toggle the flashlight on and off
function ToggleFlashlight () {
   if(energy>1){
       turnedOn=!turnedOn;
      audio.PlayOneShot(shootSound);
    if (turnedOn  energy>0) {
       TurnOnAndDrainEnergy();
    } else {
       lightSource.enabled = false;
    }
    }
} 
 
 
//When the flashlight is turned on we enter a while loop which drains the energy
function TurnOnAndDrainEnergy () {
    lightSource.enabled = true;
    while (turnedOn  energy>0) {
       energy -= drainSpeed*Time.deltaTime;
       if(energy < 600){
           animationComp.Play("AnimacionFlashLight"); //change to what you need it to be.
       }
       yield;
    }
    lightSource.enabled = false;
}
 
//This is called from outside the script to alter the amount of energy
static function AlterEnergy (amount : int) {
    energy = Mathf.Clamp(energy+amount, 0, 100);
}
function ToggleFlashlight () {

   if(energy>1){

       turnedOn=!turnedOn;

      audio.PlayOneShot(shootSound);

    if (turnedOn  energy>0) {

       TurnOnAndDrainEnergy();

    } else {

       lightSource.enabled = false;
      if(animationComp.isPlaying){
      animationComp.Stop("AnimacionFlashLight");
       }
    }

    }

}

I solved it!, but i don’t know how to delete the post, thanks a lot:)