> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-traffic-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gley.gitbook.io/mobile-traffic-system/delegates/traffic-lights-behaviour.md).

# Traffic Lights Behaviour

## Description

Controls the behavior of the lights inside a traffic light intersection.

## Declaration

```csharp
 public delegate void TrafficLightsBehaviour(TrafficLightsColor currentRoadColor, List<GameObject> redLightObjects, List<GameObject> yellowLightObjects, List<GameObject> greenLightObjects, string name);
```

## Parameters

<table><thead><tr><th width="203">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>currentRoadColor</strong></td><td>The current color that is on this road specified by the Traffic System .</td></tr><tr><td><strong>redLightObjects</strong></td><td>The list of the red lights objects assigned in editor.</td></tr><tr><td><strong>yellowLightObjects</strong></td><td>The list of the yellow lights objects assigned in editor.</td></tr><tr><td><strong>greenLightObjects</strong></td><td>The list of the green lights objects assigned in editor.</td></tr><tr><td><strong>name</strong></td><td>The name of the intersection.</td></tr></tbody></table>

## Set Method

```csharp
public static void SetTrafficLightsBehaviour(TrafficLightsBehaviour trafficLightsBehaviourDelegate)
```

## Example

```csharp
using Gley.TrafficSystem;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    private void Start()
    {
        Delegates.SetTrafficLightsBehaviour(MyTrafficLightBehaviour);
    }

    void MyTrafficLightBehaviour(TrafficLightsColor currentRoadColor, List<GameObject> redLightObjects, List<GameObject> yellowLightObjects, List<GameObject> greenLightObjects, string name)
    {
        switch (currentRoadColor)
        {
            case TrafficLightsColor.Red:
                //color is red -> show red lights
                break;
            case TrafficLightsColor.Green:
                //color is green -> show green lights
                break;
            case TrafficLightsColor.YellowGreen:
                //color is yellow and before was green -> show yellow lights
                break;
            case TrafficLightsColor.YellowRed:
                //color is yellow and before was red -> show yellow lights
                break;
        }
    }
}
```

{% hint style="info" %}
Default delegate implementation can be found inside **DefaultDelegates.cs**
{% endhint %}
