How to make Flashlight timer.

Hi i have this script for my flashlight turn on and off, and play audio,

var linkedLight : Light;
var shootSound:AudioClip;

function Update () {
if(Input.GetKeyDown(“f”)){
linkedLight.enabled = !linkedLight.enabled;
audio.PlayOneShot(shootSound);
}
}

but i need to add a script when I have caught a long time is running out

thanks a lot

Make a float var like ‘capacity’ and set it to some number. In Update, if the light is enabled, subtract a small amount from capacity. When it gets to zero, turn the light off. For extra fun, you might want to wait until the capacity is about 10%, then start setting the light’s intensity to smaller values until it reaches zero.