Trigger Lights in Unity

Basically, I want my character to walk up some stairs and trigger spotlights as he goes up.
I’m not good at all with scripting, so I just need it to be as basic as possible.
How would I trigger the lights using box colliders? if someone could explain it clearly, as I’m new to unity.

Have a script like this on your box trigger. Then plug your light into the lightObject variable. Once the player enters the trigger, the light will go on.

var lightObject : Transform;

function OnTriggerEnter (other : Collider) {

lightObject.light.enabled = false

}

If you want the light to turn off once the player leaves the area, thats a little more complicated with triggers. You could put a script on the light that constantly checks the distance from the player. Although it might be a waste to have a update function running all the time just for the light.

You can just use OnTriggerExit. Also it’s best to directly refer to the component you’re going to use, and not to use the Collider variable in OnTriggerEnter if you’re not referencing the other object in the trigger, so ideally it would be

var lightObject : Light;

function OnTriggerEnter () {
    lightObject.enabled = true;
}

function OnTriggerExit () {
    lightObject.enabled = false;
}

–Eric

Yeah that’s better. However the OnTriggerExit can be activated once the player stops intersecting with a face/polygon. So they could pass into a box trigger, but if they are inside the box and not touching any sides, the onTriggerExit will be called even though they are still inside of the area.

I don’t know what you mean by “Then plug your light into the lightObject variable”?

Basically, I made a light and a box collider (selected is trigger), and I added the script to the box collider as given.
How do I connect the light and the collider? Is this done in the code?

If you look at the script in the inspector, the lightObject variable should be exposed. Drag your light onto the lightObject variable in the inspector. You’ve now assigned the lightObject variable to your light. Now the ‘‘lightObject’’ will reference the light in the script.

that code gives me an error and i double checked the syntax.
The other code doesn’t give an error but doesn’t work and i’ve dragged the light into the variable

What is the error? I forgot a semicolon with mine.