So, in my game there’s a lighter in your hand. I have changed a flashlight script to achieve what I wanted… But what I want to add now is a system so that if you have the lighter on for more than… Lets say 60 secs, the lighter will go out. If someone could maybe show me how that’s added into a script it would be much appreciated. Here’s my current script. Thanks.
Inside your update function, you would have a timer (starting from 60 or whatever value you prefer) counting down. So when it has reached to 0 or less, you have exceeded 60 seconds then set your boolean LightOn to be false. The rest of your script will take care of itself.
if(LightOn) // if your light is turned on
{
if(timer <= 0)
{
LightOn = false;
}
else
{
timer -= Time.deltaTime;
}
}
Of course, it’s a good idea to reset your timer to 60 when your turn your light off.
I added in this into the script, under the function update. I got an error for the timer (unknown identifier) so then I thought maybe it needs a variable, added one in as such… “var timer : int = 10;” (10 just for testing) It got rid of the error… but the timer is going down almost immediately and the light isn’t going, also the input isn’t working. I’m thinking It’s either a wrong variable, or Iv’e put something in the wrong place? I’ll post the script as it is below. Thanks again.