Why has a script I created altered every instance of an object?

I was trying to make some lighting effects. For lack of a more immediate solution (other than just copying and pasting online, I’m trying to figure out some problems on my own to learn), I wrote the following script for a strobe light effect.

using UnityEngine;
using System.Collections;

public class LightStrobeEffect : MonoBehaviour {

	public float MinimumIntensity = 0.0f;
	public float MaximumIntensity = 1.5f;
	public int SwitchTimer = 10;

	private bool lightOn = true;
	private int timer = 0;

	// Use this for initialization
	void Start () {
		this.light.intensity = MaximumIntensity;
	}
	
	// Update is called once per frame
	void Update () {
		timer++;

		if (timer % SwitchTimer == 0) {
			if (lightOn) {
				this.light.intensity = MinimumIntensity;
				lightOn = false;
			} else {
				this.light.intensity = MaximumIntensity;
				lightOn = true;
			}
			timer = 0;
		} else {
			// I don't know of anything that would go here, but it's available
			// just in case future updates require it.
		}
	}
}

Essentially, what the code does it this: three new variables are exposed in the editor. MinimumIntensity, MaximumIntensity, and SwitchTimer, with default values assigned for each. The first two are self-explanatory, and SwithTimer determines how many frames will pass before switching from on to off or vice-versa. The code simply counts up each frame and checks if the value is a multiple of SwitchTimer via a modulus. If so, switch things around.

I added the script to a light and it worked. I was expecting some quirk or coding error to cause revisions to happen, but everything seemed fine right away. Except that the strobe effect has been applied to the other point lights in my scene as well. I double-checked and the script has not been added to the entities themselves, only to the one light I was testing on. But the strobe effect continues to exist on every light. This happens when I run the scene in the editor and when I build and run as a stand-alone executable.

So the question is: why is this happening and what can I do to fix it?

tl;dr: I made a scripted light effect and applied it to a single light but it affects every light; why?

Update: I seem to have narrowed the problem a little bit. I added a new point light to the world and this one does not seem to be affected. The light that IS affected also has a custom script on it. I am attaching it below:

using UnityEngine;
using System.Collections;

public class LightToggle : MonoBehaviour {

	private bool activated = true;
	private float oldIntensity;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void ToggleLight () {
		if (activated) {
			activated = false;
			oldIntensity = light.intensity;
			light.intensity = 0.0f;
		} else {
			activated = true;
			light.intensity = oldIntensity;
		}
	}
}

The trigger that toggles the light has the following script:

using UnityEngine;
using System.Collections;

public class TriggerToggleLight : MonoBehaviour {

	public LightToggle LightToToggle;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnTriggerEnter(Collider other) {
		
		LightToToggle.ToggleLight();
	}
}

So if it is a matter of how I am programming my scripts, what am I doing wrong and how can I avoid it in the future?

There wasn’t a problem. Apparently the interaction of the lights on a checkered background (using the prototyping textures from the beta sample assets) created the optical illusion that one light was changing as the other was changing. By making the lights contrasting colors and changing the range to be much shorter and out of the area that the lights could “interact” in the middle, the lack of a problem was apparent.

Sorry for the trouble, everyone. Please carry on, I’ll see myself out now.
~ TrueKam

I really wanna say it’s because you’re using

this.light

If this script is set to a light object, use

gameObject.light

If not, create a

public GameObject eLight

and use

this.eLight.light