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.

Parameters in inspector

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:
[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:
Last updated