- Home /
Question by
killerbat · Apr 02, 2013 at 08:30 AM ·
timerflashlight
Flash light timer
I want to set a time for my flashlight to turn off,can any one help me out please? heres my script for my flashlight and sound.
private var lightSource : Light;
var soundTurnOn : AudioClip;
var soundTurnOff : AudioClip;
function Start () {
lightSource = GetComponent(Light);
}
function Update () {
if (Input.GetKeyDown(KeyCode.F)) ToggleFlashLight();
}
function ToggleFlashLight () {
lightSource.enabled=!lightSource.enabled;
//Audio
if (lightSource.enabled) {
audio.clip = soundTurnOn;
} else {
audio.clip = soundTurnOff;
}
audio.Play();
}
@script RequireComponent(AudioSource)
Comment
Answer by cdrandin · Apr 02, 2013 at 08:46 AM
Basic timer implementation
float timer;
int waitingTime;
void Update(){
timer += Time.deltaTime;
if(timer > waitingTime){
//Action
timer = 0;
}
}