// Update is called once per frame void Update() { if (timer >= RedTime && LightState == TrafficLightStateType.RED) { timer = 0f; LightState = TrafficLightStateType.GREEN; } else if (timer >= AmberTime && LightState == TrafficLightStateType.AMBER) { timer = 0f; LightState = TrafficLightStateType.RED; } else if (timer >= GreenTime && LightState == TrafficLightStateType.GREEN) { timer = 0f; LightState = TrafficLightStateType.AMBER; } else if (timer >= OffTime && LightState == TrafficLightStateType.OFF) { timer = 0f; LightState = TrafficLightStateType.RED; } UpdateLightObject(); timer += Time.deltaTime; }
private float timer = 0f; // time in secs // Use this for initialization void Start() { LightState = TrafficLightStateType.RED; AmberOffColor = new Color(.60f, 0.60f, 0.36f); AmberOnColor = new Color(1.0f, 0.90f, 0); RedOffColor = new Color(.30f, 0.14f, 0.14f); RedOnColor = new Color(1f, 0, 0); //GreenOffColor = new Color(0.27f,0.40f,0.30f); GreenOffColor = new Color(0.140f, 0.20f, 0.14f); GreenOnColor = new Color(0, 1f, 0); RedLightChild = this.transform.Find("RedLight").gameObject; AmberLightChild = this.transform.Find("AmberLight").gameObject; GreenLightChild = this.transform.Find("GreenLight").gameObject; PointLightChild = this.transform.Find("Point light").gameObject; PointLightComponent = PointLightChild.GetComponent <Light>(); UpdateLightObject(); }