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 && currentLight != 3) { ChangeLight(3); currentLight = 3; } } private void ChangeLight(int lightToSet) { //turn off all lights RedLight.GetComponent().material.SetColor("Black", BlackColor); YellowLight.GetComponent().material.SetColor("Black", BlackColor); GreenLight.GetComponent().material.SetColor("Black", BlackColor); switch (lightToSet) { case (1): //green GreenLight.GetComponent().material.SetColor("Green", GreenColor); break; case (2): //yellow YellowLight.GetComponent().material.SetColor("Yellow", YellowColor); break; case (3): //red RedLight.GetComponent().material.SetColor("Red", RedColor); break; } } }