Hi guys,
I have a light and a switch on a wall that when you stand close enough brings up a UI light switch slider that you can control the brightness of the lights. Do i have to create a set like this for each light in my house? doesnt seem very efficient. How can I share the one element on my UI for all lights? Is this possible?
here is my light switch code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PassageLightController : MonoBehaviour
{
public Light passageLight1;
public Light passageLight2;
public Slider lightValue;
public GameObject uiLightControl;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
uiLightControl.SetActive(true);
}
}
private void Update()
{
passageLight1.intensity = lightValue.value;
passageLight2.intensity = lightValue.value;
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
uiLightControl.SetActive(false);
}
}
}