First and formost- I need the coding to be in JAVASCRIPT not C SHARP
Hey Guys, I’ve read a couple other questions related to this, but they both involved batteries. I don’t want batteries for the flashlight in my game. I just want for the player to be able to walk over to a table, and click E to pickup the flashlight. BUT I do want them to be able to turn it on and of with the F key.
I already have the script for the flashlight turning on and off writen, I just dont now how to incorporate the whole PICKUP part off it where they wont me able to turn it on until they pick it up. This is what I have so far.
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)
@script RequireComponent(Light)