I’ve been having a browse on here for a while and haven’t come up with a way to fix my script. Basically I have an energy bar for a flashlight, it works fine but it counts way too quick, I was wondering how I could slow it down so that I can use seconds instead of frames. If I set the number for the flashenergy to 600 or so the energy bar works correctly but it starts to make the game lag.
public static var flashon: int = 0;
public static var flashlevel: float = 0;
function Start () {
light.enabled = false;
}
function Update() {
if (Input.GetKeyDown("f")) {
audio.Play();
if (light.enabled == true)
light.enabled = false;
else
light.enabled = true;
flashon = 1;
}
if (flashlevel == 100){
light.enabled = false;
}
if (light.enabled == false){
flashon = 0;
}
if (flashon == 1){
if (flashlevel <100)
flashlevel += 1;
InvokeRepeating ("Countdown", 1.0, 1.0);
}
if (flashon == 0){
if (flashlevel >0)
flashlevel -= 2;
InvokeRepeating ("Countdown", 1.0, 1.0);
}
}
Any help would be much appreciated.