I wanted to share how I made the day-night cycle in Unity for BOAT.
First I compute the day progression to have a number that ping pong between 0 and 1. 0 being the day and 1 the night. It looks like that:
cs
_time += Time.deltaTime;
float timeIn012 = Mathf.PingPong(_time / _secondForOneHour, 12);
_progression = timeIn012/12f;
Then I'm changing the intensity of the main directional light and the skybox to reflect that progression:
```cs
// Directional light
directionalLight.intensity = Mathf.Lerp(maxLightIntensity, _minLightIntensity, _progression);
// Skymap
float exposure = Mathf.Lerp(maxExposure, _minExposure, _progression);
Color skyColor = Color.Lerp(skyDayColor, skyNightColor, _progression);
RenderSettings.skybox.SetFloat("Exposure", exposure);
RenderSettings.skybox.SetColor("GroundColor", skyColor);
RenderSettings.skybox.SetColor("SkyTint", skyColor);
DynamicGI.UpdateEnvironment();
```
The skybox update is a little slow so you probably don't want to do it every frames. One update every second should be enough. At the end you have a method that looks like that:
```cs
private void Update()
{
_time += Time.deltaTime;
_updateParamsTime += Time.deltaTime;
if (_updateParamsTime >= 1f)
{
_updateParamsTime = 0f;
float timeIn012 = Mathf.PingPong(_time / _secondForOneHour, 12);
_progression = timeIn012/12f;
// Directional light
_directionalLight.intensity = Mathf.Lerp(_maxLightIntensity, _minLightIntensity, _progression);
// Skymap
float exposure = Mathf.Lerp(_maxExposure, _minExposure, _progression);
Color skyColor = Color.Lerp(_skyDayColor, _skyNightColor, _progression);
RenderSettings.skybox.SetFloat("_Exposure", exposure);
RenderSettings.skybox.SetColor("_GroundColor", skyColor);
RenderSettings.skybox.SetColor("_SkyTint", skyColor);
DynamicGI.UpdateEnvironment();
}
}
```
You can make the _progression available for other component, to be able to activate some lights when the night is here.
How it looks in game:

If you want to see what it looks like in realtime you can checkout my game.
You have better ideas on how to implement it, I'm taking it.