How can I disable all objects with the same name?

In my Options screen I want to make a button, which will disable all dynamic light in my scene.
But the problem is that all my light sources are in the different places in the Hierarchy, so I can’t just disable one object.

Can I find all lights using search and enable/disable them in the script like on he screenshot?

43774-1.jpg

Or the best thing which I can do is to create a public array and put all lights to that by hands?

private Light lights;
void Start () {
lights = FindObjectsOfType(typeof(Light)) as Light;
foreach(Light light in lights)
{
light.intensity = 0;
}
}

You could use GameObject.Find(“AscentLight”) to find them.

GameObject light = GameObject.Find("AscentLight");
do {
    light.setActive(false);
    light = GameObject.Find("AscentLight");
} while (light != null);

This has some quirks, like it can only turn the lights off and not back on, since GameObject.Find doesn’t return inactive objects and you can’t loop like this unless you set them as inactive.

So it can be enhanced to keep track of disabled lights in a list, and when you try to re-enable the light you go from that list instead of using this.