using System.Collections; using System.Collections.Generic; using UnityEngine; using TrafficSimulation; public class TrafficLightHandler : MonoBehaviour { public Intersection intersection; public int lightPhase; public GameObject RedLight; public GameObject YellowLight; public GameObject GreenLight; public Color RedColor; public Color YellowColor; public Color GreenColor; public Color BlackColor; private int currentLight; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { ManageLightChanges(); } private void ManageLightChanges() { if(intersection.currentRedLightsGroup == lightPhase) { ChangeLight(3); currentLight = 3; }else{ ChangeLight(1); currentLight = 1; } } private void ChangeLight(int lightToSet) { //turn off all lights RedLight.GetComponent().material.color = BlackColor; YellowLight.GetComponent().material.color = BlackColor; GreenLight.GetComponent().material.color = BlackColor; switch (lightToSet) { case (1): //green GreenLight.GetComponent().material.color = GreenColor; break; case (2): //yellow YellowLight.GetComponent().material.color = YellowColor; break; case (3): //red RedLight.GetComponent().material.color = RedColor; break; } } }