Exemple #1
0
    void OnDrawGizmos()
    {
        Gizmos.color = Color.Lerp(Color.red, Color.yellow, 0.5f);
        Gizmos.DrawWireCube(transform.position, Vector3.one * Width);

        Gizmos.color = Color.cyan;

        foreach (Road r in roads)
        {
            if (r.type == RoadType.North)
            {
                Gizmos.color = Color.yellow;
            }
            else if (r.type == RoadType.South)
            {
                Gizmos.color = Color.red;
            }
            else if (r.type == RoadType.East)
            {
                Gizmos.color = Color.blue;
            }
            else
            {
                Gizmos.color = Color.cyan;
            }

            Gizmos.DrawLine(r.GetStartPosition(), r.GetEndPosition());
        }

        // show the passing situation
        Gizmos.color = Color.green;
        if (IsPassing(RoadType.North) || IsPassing(RoadType.South))
        {
            Gizmos.DrawLine(transform.position + transform.forward * Width / 2f
                            , transform.position - transform.forward * Width / 2f);
            trafficLightScript.DisplayPassingNS();
        }
        else if (IsPassing(RoadType.East) || IsPassing(RoadType.West))
        {
            Gizmos.DrawLine(transform.position + transform.right * Width / 2f
                            , transform.position - transform.right * Width / 2f);
            trafficLightScript.DisplayPassingWE();
        }
        else
        {
            Gizmos.color = Color.red;
            Gizmos.DrawLine(transform.position + transform.forward * Width / 2f + transform.right * Width / 2f,
                            transform.position - transform.forward * Width / 2f - transform.right * Width / 2f);
            Gizmos.DrawLine(transform.position - transform.forward * Width / 2f + transform.right * Width / 2f,
                            transform.position + transform.forward * Width / 2f - transform.right * Width / 2f);
        }
    }