Toggling point light on/off when clicking a key in a triggered Box Collider area

Hi everyone, I’m currently working on a horror game and I’ve being spending hours by making scenes and models. I’ve learned about Mesh Colliders a few months ago and how the “Is Trigger” function works. I’ve placed a bunch of ceiling lamps to make my scene look brighter and what I need, as the title says; A script for being able to toggle lights when closing up an object (For example, clicking the E button to open/close lights when near the light switch)

I’ve setup my Capsule Collider with his appropriate scale and range plus with the “Is Trigger” function checked, and yes, my point light is attached with my ceiling lamp.

If you guys have great ideas for making a kind of script like this, please post them as an answer below! I would really appreciate your supports :slight_smile:

As always, thanks!

-crusherxman

this can be simply done in javascript with a .active statement. for example :

var Lights : GameObject;
var InArea : boolean = false;
var LightsOnAndInArea : boolean = false;
var LightsOffAndInArea : boolean = false;

function Start ()
{
	Lights.active = true;
}

function Update ()
{
	if(Input.GetKeyDown(KeyCode.E) && LightsOnAndInArea == true){
    	Lights.active = false;
    }
    if(Input.GetKeyDown(KeyCode.E) && LightsOnAndInArea == false){
    	Lights.active = true;
    }
    	
    if(Lights.active == true && InArea == true){
    	LightsOnAndInArea = true;
    }
    if(Lights.active == false && InArea == true){
    	LightsOnAndInArea = false;
    }
    
    if(Lights.active == true && InArea == false){
    	LightsOnAndInArea = false;
    }
    if(Lights.active == false && InArea == false){
    	LightsOnAndInArea = false;
    }
}
    
function OnTriggerEnter (other : Collider) 
{
    InArea= true;
}
    
function OnTriggerExit (other : Collider) 
{
    InArea= false;
}

There you go now you can toggle on and off

Daphoeno