Simulating the MRT display board

There are few information required to start the simulation

  1. The Line which the train is on: North East line, North South Line and Changi Line
  2. The Direction which the train is travelling
  3. Next Station
  4. Door Opening Side for Next Station


First we create and name all the lights for each line






next we will setup the script to display the information provided by the public variables. Note the blinking light uses a Coroutine function.

using UnityEngine;
using System.Collections;
using System;

public class TrainLightDisplay : MonoBehaviour {

    public GameObject NELine;
    public GameObject NSLine;
    public GameObject CGLine;

    public int Line;
    public bool MovDirection;
    public bool DoorDirection; 
    public string NextStation;

    private Light[] lightsDisp;

    // Use this for initialization
    void Start () {
        if(Line != null){
        switch(Line)
            {
            case 0: 
                Debug.Log("North East Line Activated");
                NELine.SetActive(true);
                lightsDisp = NELine.GetComponentsInChildren<Light>();
                if(!MovDirection){
                Array.Reverse(lightsDisp);
                }
                foreach(Light Lit in lightsDisp){
                    Lit.gameObject.SetActive(false);
                    Debug.Log(Lit.name);                    
                    if(Lit.name == NextStation){
                        Lit.gameObject.SetActive(true);
                        Lit.color = Color.red;
                        StartCoroutine(Toggler (Lit));
                        break;
                    }

                }
                break;
            case 1: 
                Debug.Log("North South Line Activated");
                NSLine.SetActive(true);
                lightsDisp = NSLine.GetComponentsInChildren<Light>();
                if(!MovDirection){
                Array.Reverse(lightsDisp);
                }
                foreach(Light Lit in lightsDisp){
                    Lit.gameObject.SetActive(true);
                    Debug.Log(Lit.name);

                    if(Lit.name == NextStation){
                        Lit.gameObject.SetActive(true);
                        Lit.color = Color.red;
                        StartCoroutine(Toggler (Lit));
                        break;
                    }

                }
                break;
            case 2:
                Debug.Log("Changi Line Activated");
                CGLine.SetActive(true);
                lightsDisp = CGLine.GetComponentsInChildren<Light>();
                if(!MovDirection){
                Array.Reverse(lightsDisp);
                }
                foreach(Light Lit in lightsDisp){
                    Lit.gameObject.SetActive(true);
                    Debug.Log(Lit.name);

                    if(Lit.name == NextStation){
                        Lit.gameObject.SetActive(true);
                        Lit.color = Color.red;
                        StartCoroutine(Toggler (Lit));
                        break;
                    }
                }
                break;
            }

        }
    }

    IEnumerator Toggler(Light Lit)
    {
            yield return new WaitForSeconds (0.5f);
            Lit.enabled = !Lit.enabled;
            StartCoroutine(Toggler(Lit));
    }

}

The result of this script is user can specific the mrt line, direction and a station name, for example: North East Line, Forward, N08. This display board will display the coming station(N08) in flashing red light and covered stations no light and future stations in green light.

displayImage