using Enviro; using System.Collections; using System.Collections.Generic; using UnityEngine; using static UnityEngine.Rendering.DebugUI.Table; public class LightManager : MonoBehaviour { public enum SwitchCondition { turnON,turnOFF}; SwitchCondition currentCondition; SwitchCondition lightCondition; private List streetLightingAndAutomativeLighting; // Start is called before the first frame update void Start() { var streetLightings=GameObject.FindGameObjectsWithTag("StreetLighting"); var automativeLightings = GameObject.FindGameObjectsWithTag("AutomativeLighting"); streetLightingAndAutomativeLighting = new List(); for (int i = 0; i < streetLightings.Length; i++) { streetLightingAndAutomativeLighting.Add(streetLightings[i].GetComponent()); } for (int i = 0; i < automativeLightings.Length; i++) { streetLightingAndAutomativeLighting.Add(automativeLightings[i].GetComponent()); } UpdateLight(); } // Update is called once per frame void Update() { //System.DateTime now = System.DateTime.Now; int hour = Enviro.EnviroManager.instance.Time.hours; if (hour >= 6 && hour <= 18) { currentCondition = SwitchCondition.turnOFF; } else { currentCondition = SwitchCondition.turnON; } if (currentCondition != lightCondition) { UpdateLight(); } } void UpdateLight() { int hour = Enviro.EnviroManager.instance.Time.hours; //System.DateTime now = System.DateTime.Now; if (hour >= 6 && hour <= 18)//°ΧΜμ { lightCondition = SwitchCondition.turnOFF; foreach (var light in streetLightingAndAutomativeLighting) { light.enabled = false; } } else//ΝνΙΟ { lightCondition = SwitchCondition.turnON; foreach (var light in streetLightingAndAutomativeLighting) { light.enabled = true; } } } }