FlashLight with battery power

var Batlife: int;
var linkedLight : Light;
var mySkin : GUISkin;
var style1 = mySkin.customStyles[0];

function Awake() {
    GUI.skin = mySkin;
 GUI.Label (Rect(40, Screen.height - 50,60,60)," Battery: ");
 GUI.Label (Rect(100, Screen.height - 50,60,60),"" +Batlife, style1);
}
function Update () {
    if(Input.GetKeyDown("f")){
        linkedLight.enabled = !linkedLight.enabled;
   }
}

function LightOff (){
 linkedLight.enabled = false;
} 

thats ,my current flashlight script… its pretty nooby.

Kay what i want to do is have battery power.
i know how to make variables but have no idea how to
relate it withen this

pretty much starting battery power is 100%
And every 3 seconds it drains by 10%
when battery power is 0 the flashlight will not come on.

can anyone help me do this?

Here’s an example of some of the code you’d need:

public var maxBatteryLife: float = 100.0f;
public var batteryLifeLostPerSecond: float = 3.0f;
public var linkedLight: Light;

public var currentBatteryLife: float;

function Start() {
    currentBatteryLife = maxBatteryLife;
}

function Update() {
    if (Input.GetKeyDown("f")) {
        linkedLight.enabled = !linkedLight.enabled; // Toggles the light
    }
    if (linkedLight.enabled) {
        currentBatteryLife -= batteryLifeLostPerSecond * Time.deltaTime; // Reduces the battery correctly over time
    }
    if (currentBatteryLife <= 0) {
        linkedLight.enabled = false; // Keeps the light off when there is no power.
    }
}

var BatteryLife : int;
var linkedLight : Light;
var TakeLifeInterval: int

function Start () {
   BatteryLife = 100
   TakeLifeInterval = 0.2
}
function Update () {
if(Input.GetKeyDown("f")){
        linkedLight.enabled = true;
        BatteryLife = BatteryLife-TakeLifeInterval

   }
if(Input.GetKeyUp("f")){
        linkedLight.enabled = false;
   }
}

I Set TakeLife Interval to 0.,2 so it doesnt take all power every time we run the Update Function. you can change the values, either the BatteryLife, or the TakeLifeInterval to siut your specific times and needs.