- Home /
Add delay to javascript?
Hello, Let me make this quick. I'm using this script for a flashlight. http://pastebin.com/Fud2euBT Now under the section " batteryLife = Mathf.Clamp(batteryLife+batteryPower, 350, 99)" the script is "replacing the battery". Now my question is: How to add and where to add that the flashlight turns off for an amount of time and then turn on again? I mean like to set like: When the battery starts to reload, set spotlight intensity to 0. After the set amount of time (6 seconds for example) then the intensity should be set to "1.35". Please help! Thanks!
Answer by Jason2014 · Jun 23, 2017 at 10:10 AM
function ReplaceBattery ()
{
flashlightLightSource.intensity = 0;
yield WaitForSeconds (6);
flashlightLightSource.intensity = 1.35f;
}
This is the simplest example of delaying commands. Call this function there where you want to replace that battery.
Your answer
Follow this Question
Related Questions
Luz parpadeante con bateria 0 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Realtime spotlight shadows constantly flicker 1 Answer
Enable/Disable Scripts 3 Answers
Flashlight battery script 3 Answers