RedLightStatus.cs 838 B

123456789101112131415161718192021222324252627282930313233
  1. // Traffic Simulation
  2. // https://github.com/mchrbn/unity-traffic-simulation
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using TrafficSimulation;
  7. public class RedLightStatus : MonoBehaviour
  8. {
  9. public int lightGroupId; // Belong to traffic light 1 or 2?
  10. public Intersection intersection;
  11. Light pointLight;
  12. void Start(){
  13. pointLight = this.transform.GetChild(0).GetComponent<Light>();
  14. SetTrafficLightColor();
  15. }
  16. // Update is called once per frame
  17. void Update(){
  18. SetTrafficLightColor();
  19. }
  20. void SetTrafficLightColor(){
  21. if(lightGroupId == intersection.currentRedLightsGroup)
  22. pointLight.color = new Color(1, 0, 0);
  23. else
  24. pointLight.color = new Color(0, 1, 0);
  25. }
  26. }