In my project I’m trying to make a flashlight but am stuck. I figured it would be connecting a point light to a object similar to making a gun, but am stuck on getting the flashlight to turn on and off. I want it to turn on/off with the left mouse button, but don’t know how to. Can anyone help with this?
Links:
Scripting Reference:
Similar question:
There are loads of stuff addressing how to turn stuff on/off the only thing you’ll have to do is search.
Place this script on your flashlight (assuming, of course, that you have your light component attached to that object):
var flashlight : Light;
function Start () {
flashlight = GetComponent("Light");
}
function Update () {
if (Input.GetMouseButtonDown(0)) {
if (flashlight.enabled) {
flashlight.enabled = false;
} else {
flashlight.enabled = true;
}
}
}
Hope that helps! Klep