# Day Time Controller

Presented by `IDayTimeController` interface, this system allows to simulate switching between day and night.

To use it, just add DayTimeController prefab onto your game scene and set it up as you wish.

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FsFQAWIiZoxKjMhWuDcKU%2Fimage.png?alt=media&#x26;token=82fd0bba-1b64-4a8c-856f-70471dad2855" alt=""><figcaption><p>DayTimeController prefab</p></figcaption></figure>

### Parameters in inspector

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FasPlj2sx98J7ANerwzKJ%2Fimage.png?alt=media&#x26;token=e7d80604-1706-4a7a-b8d1-d0cc4274a230" alt=""><figcaption><p>Parameters in inspector</p></figcaption></figure>

**Sun** – reference to Light source which will be moved

**Day Length** – length of day in seconds

**Night Length** - length of night in seconds

**Time Of Day** – initial time of day (from 0 to 1, where 0 is sunrise, 0.5 is sunset and 1 is sunrise again).

***

You can also set current time of day via code. For this, you need to inject this system to needed class and call `SetTimeOfDay` method, like shown below:

```csharp
[Inject] private IDayTimeController dayTimeController;

private void ExampleMethod()
{
    // 0 is sunrise
    dayTimeController.SetTimeOfDay(0f);
    
    // 1 is sunrise too
    dayTimeController.SetTimeOfDay(1f);

    // 0.5 is sunset
    dayTimeController.SetTimeOfDay(0.5f);
}
```

You should pass number from 0 to 1 as parameter, where 0 is sunrise, 0.5 is sunset and 1 is sunrise again. It's easier to understand with this simple diagram:



<img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FAPfAyJhmVJbBsw4JkySA%2Ffile.excalidraw.svg?alt=media&#x26;token=a7c61975-4e3a-4950-9624-852343414078" alt="Sun movement diagram" class="gitbook-drawing">

***

{% hint style="info" %}
You can see how it works on the `WeatherTestScene`, which is situated in `Assets/Heroic Engine/Example/Scenes` directory.
{% endhint %}
