Dynamic Day/Night Cycle: Lite cover art
Documentation

Dynamic Day/Night Cycle: User Manual

Real-time day-night lighting for Unity. Controls ambient light, sun direction, fog, water tint, and an in-game UI clock with smooth transitions between four lighting profiles. Day Night Cycle Lite for Unity, Unity day night lighting, Unity time of day system, Unity dynamic lighting, Unity ambient lighting, Unity sun direction control, Unity fog control, Unity water tint control, Unity UI clock, Unity lighting transition.

Overview

The DayNightCycle component simulates a full day-night lighting cycle in real time, controlling ambient lighting, sun direction, fog, water color, and updating a UI clock.

Supports:

  • Smooth time progression
  • Manual time setting
  • Scene-wide lighting transitions
  • Fog and water color blending
  • Runtime and editor-friendly workflow

Component Setup

Attach the DayNightCycle.cs script to a GameObject (typically an empty GameObject called DayNightController).

Required assignments

  • sunLight: the main directional light representing the sun. This is a child of the rotationPivot.
  • rotationPivot: a Transform whose X rotation simulates the sun’s movement.
  • sceneCamera: Camera for background color transitions.
  • timeText (optional). TextMeshProUGUI object for displaying the in-game clock.
  • waterRenderer (optional). Renderer for the water surface.
  • waterColorProperty: Name of the water color shader property (_WaterColor by default). This can be changed to match your specific shader.

Inspector Settings

Time Settings

  • startTimeOfDay: Hour of the day at scene start (0-24).
  • cycleSpeed: Time progression speed multiplier.
  • TimeOfDay (read-only). Current in-game time.

Reset Settings

  • resetSpeed: Speed at which time resets smoothly.
  • forwardsOnly: Forces time resets to only move forward.

Directional Light Settings

  • rotationOffsetY: Y-axis rotation offset for the sun’s path. This lets you control rotation angle in the scene.

Fog Control

  • enableFogControl: If true, fog color and density are controlled automatically.

Water Settings

  • waterRenderer: Renderer using the water shader.
  • waterColorProperty: Shader property controlling water color. This uses MaterialPropertyBlocks.

Lighting Time Settings

Four lighting profiles. Click the buttons at the bottom of the component to set those values:

  • Daybreak
  • Midday
  • Sunset
  • Night

Each profile includes:

  • ambientColor
  • sunColor
  • backgroundColor (camera background color)
  • sunIntensity
  • shadowStrength
  • fogColor (if enabled)
  • fogDensity
  • waterColor

These define the scene’s environmental settings for that time period and automatically blend between them.

Runtime Controls (Public Methods)

Call these methods from other scripts, UI buttons, or events:

MethodDescription
StopTime()Pause time progression
StartTime()Resume time progression
ResetToStartTime()Smoothly reset time to startTimeOfDay
SetToDaybreak()Instantly set time to 6:00
SetToMidday()Instantly set time to 12:00
SetToSunset()Instantly set time to 18:00
SetToNight()Instantly set time to 0:00

How It Works

  • Update(): Increments _timeOfDay based on cycleSpeed.
  • UpdateLighting(): Calculates sun rotation and interpolates environment settings between the two closest time profiles.
  • UpdateTimeUI(): Updates the on-screen time display once per minute change.
  • ResetTimeSmoothly(): Smoothly interpolates _timeOfDay over time when called.

Best Practices

  • Use rotationPivot as the parent of the sun light for easier Y-axis control.
  • If using custom fog or water solutions, disable enableFogControl or clear the waterRenderer reference.
  • Keep cycleSpeed low for realistic day-night transitions (e.g., 0.05 to 0.2).

Example Setup. Quick Start

GameObject: DayNightController Attach Script: DayNightCycle

Assign references:

  • sunLight → Your main Directional Light (Sun). You can adjust the Y rotation to simulate the Sun’s height at different times of the year.
  • rotationPivot → Empty GameObject or the parent of the sun light.
  • sceneCamera → Main Camera.
  • timeText → TextMeshProUGUI object (optional).
  • waterRenderer → Water plane renderer (optional).

For support please contact itsmakingthings@gmail.com.