Switch multiple lights On/Off ?

Hi, I’m a beginner using Unity and C# so please bare with me if I don’t have the tech vocabulary.

So, I have a room with lights on walls and sealing.

The Character (first-person) must interact/hit a cube (switch) on the wall to turn lights on/off.

Because I have multiple lights in this scene, the lights from the room are child to an empty game object with “roomLights” tag.

The character must hit the switch to turn off/on only the room lights (event/trigger to target the roomLights tag).

I’ve watched some tutorials but some of them are old and using javascript which is a no-no for me.

Any directions or maybe the C# sample would be helpful.

Thank you.

There are many diferent ways of doing that. The code line you are interested on is “gameObject.SetActive(true); and gameObject.SetActive(false);” you can also “lightcomponent.enable = true; or = false;” I usually use setactive becouse i become a little paranoid sometimes having a component still working even if i disable it.

And this being said, you have to figure out how to reach that code, you can do it from a simple trigger to a complex Raycast system. If i’m not wrong you can do it with OnMouseDawn () function to. It was a long since the last time i use OnMouseDawn so i cant recomend it. But if you want the character not only to be close to the switch but also looking at it, you should use either OnMouseDawn or Raycast.

So I have this script applied to an object switch that can switch on/off only one light, how can I modify it so that I can insert multiple lights in the editor? Do I need to use an array? How is it done in the editor? Many thanks

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.SceneManagement;
     using UnityEditor;
     
     
     public class LightSwitchObj : MonoBehaviour
     {
         public GameObject linkedLight;
         private bool lightStatus = false;
         
         void OnMouseDown()
         {
     
             if (lightStatus == false)
             {
                 linkedLight.SetActive(true);
                 lightStatus = true;
             }
             else if(lightStatus == true)
             {
                 linkedLight.SetActive(false);
                 lightStatus = false;
             }
         }
     }