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;
}
}
}