So I have a flashlight battery script I created and I need to know how do you make the battery variable go down every few seconds(whatever time you set.) I tried InvokeRepeating but it was an absolute disaster (The battery variable just went down really fast and ignored my script). Anyways this is the code I have:
void Update ()
{
if (light == false) {
battery+=0;
}
if (light == true) {
battery--;//This is what I want to have every few seconds
}
if (battery == 0) {
myLight.enabled = false;
light =false;
battery++;
InvokeRepeating("invoke", 1, 0.01F);
}
}
void invoke(){
light = false;
myLight.enabled = false;
}