Disable a light through scripting

Hello again everyone. I know this question has been asked so many times it probably makes you more advanced users want to puke when you see it but I’ve read over the documents, searched all over the forums and tried several different ways but I just can’t seem to get this to work so please bare with me while I learn :slight_smile: . Ok so what I’m trying to do exactly is have it so when the player collides with an invisible wall it disables a script called “flickeringLight” that I have attached to a light in my scene. Here’s what I have so far:

var GameObject;

function Start(){

GameObject = GameObject.FindWithTag(“light”);

GameObject.GetComponent(flickeringLight).enabled = false;

}

I keep getting an error that says: CS0201 Only assignment, call, increment, decrement and new object expressions can be used as a statement. Can someone please look over this and let me know what I’m doing wrong? Thank you for any help and input.

You can’t use “GameObject” as a variable name. Using the lowercase convention for variable names can help prevent that sort of thing (although you don’t really want to use “gameObject” either).

–Eric

I like to do it with arrays so you can add other lights if needed later.

var scriptOff : MonoBehaviour[];

function OnTriggerEnter() {
for(var s in scriptOff)
s.enabled = false;
}
//If needed
function OnTriggerExit() {
for(var s in scriptOff)
s.enabled = true;
}

If your new to arrays just add the lights to the array in the inspector. Make your wall/collider a trigger. :smile:
You can use this method for just about anything. :idea:

This might help:

function Start ( )
{
	//getting the reference to the light Object (it must be taged)
	var myLight = GameObject.FindWithTag( "light" );
	//disabling the Light
	myLight.light.enabled = false;	
}

You guys are awesome, all of your input helped immensely and it is working now :smile: thank you, thank you, THANK YOU!