private void Awake()
 {
     blockingCollider = GetComponent <Collider>(); // Get the traffic light collider
     if (GetComponentInChildren <TrafficLightBulbs>() != null)
     {
         bulbs = GetComponentInChildren <TrafficLightBulbs>(); // Get the traffic light bulbs component
     }
 }
Пример #2
0
        private void DrawLight(Graphics g, TrafficLightBulbs light)
        {
            int pictureWidth = pictureBox1.Width;
            int radius       = pictureWidth / 10;
            int centreX      = ((pictureWidth / 2) - radius) - (radius / 5);
            int centreY      = 0;

            switch (light)
            {
            case TrafficLightBulbs.TOP:
                centreY = ((this.Height / 3) - radius) - (radius / 3);
                break;

            case TrafficLightBulbs.MIDDLE:
                centreY = ((this.Height / 2) - ((radius * 2) / 3));
                break;

            case TrafficLightBulbs.BOTTOM:
                centreY = ((this.Height * 2) / 3) - (radius / 6);
                break;
            }

            Color color = Color.Black;

            if (mState == TrafficLightStates.RED && light == TrafficLightBulbs.TOP)
            {
                color = Color.Red;
            }
            else if (mState == TrafficLightStates.YELLOW && light == TrafficLightBulbs.MIDDLE)
            {
                color = Color.Yellow;
            }
            else if (mState == TrafficLightStates.GREEN && light == TrafficLightBulbs.BOTTOM)
            {
                color = Color.Green;
            }

            g.FillEllipse(new SolidBrush(color), centreX, centreY, radius * 2, radius * 2);
        }