- Home /
Turn On and Off Lights Via Script
Hi, I'm working with a car and would like to implement lights into it, which works by using a script that activates a texture and a point light to create the effect of a working brake light, but with the code that I'm using the textures work but the lights don't, how can I fix this problem?
Brake Lights Code :
var leftBrakeLight : GameObject;
var rightBrakeLight : GameObject;
var leftLightSource : Light;
var rightLightSource : Light;
function Start() {
leftBrakeLight.renderer.enabled = false;
rightBrakeLight.renderer.enabled = false;
leftLightSource.enabled = false;
rightLightSource.enabled = false;
}
function Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
leftBrakeLight.renderer.enabled = true;
rightBrakeLight.renderer.enabled = true;
leftLightSource.enabled = true;
rightLightSource.enabled = true;
}
else
if (Input.GetKeyUp(KeyCode.Space))
{
leftBrakeLight.renderer.enabled = false;
rightBrakeLight.renderer.enabled = false;
leftLightSource.enabled = false;
rightLightSource.enabled = false;
}
}
Answer by Sargoryon · Feb 16, 2013 at 05:46 PM
Maybe this will work better:
if (Input.GetKeyDown(Keycode.Space))
{
light.intensity = 1.0;
}
if (Input.GetKeyUp(Keycode.Space))
{
light.intensity = 0;
}
obs: attach it to the lights, you can make one script for each light on the car, this will give you better control of the actions involving the lights
Your answer
Follow this Question
Related Questions
turn OnMouseDrag on and off 1 Answer
Toggling the light with lightmapping(baked and dynamic shadows) 1 Answer
c# light off 2 Answers
Light script flashes on and off 1 Answer
How to make a light turn on/off 1 Answer