Hi all! I have this Javascript to make my flashlight turn on and off using the “F” key. How can I make this so instead of the “F” key it is the right mouse button?
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)