so im trying to make a toggleable flashlight with F and have the power drain over time but i cant turn the flashlight off with f, heres the script
var LightSource : Light;
static var power : float = 100;
static var turnedOn : boolean = false;
var onoffstate = false;
private var drainSpeed : float = 1.3;
function Update () {
if (Input.GetKeyDown("f")) {
if (power < 0) {
onoffstate = false;
GetComponent.<Light>().intensity = 0.0;
}
if (GetComponent.<Light>().intensity == 0.35){
onoffstate = false;
GetComponent.<Light>().intensity = 0.0;
}
if (GetComponent.<Light>().intensity == 0.0) {
GetComponent.<Light>().intensity = 0.35;
onoffstate = true;
}
}
if (onoffstate == true){
if (power > 0){
power -= drainSpeed*Time.deltaTime;
}
}
}
i also want it to display some battery textures ive made every 33% charge i dont know how to do that and im unsure why my current script doesnt work, does anyone know how to help?
What? Two same questions but not from the same author???
– Zitoox