

A simple sun rotation is not enough to make a day-night cycle feel realistic. The real atmosphere comes from smooth transitions in fog density, fog color, and ambient light intensity.
Instead of hardcoding values with if statements, the professional way to control these transitions is by using Animation Curves. Curves allow you to design how lighting and fog behave visually across the entire day.
This guide shows how to implement dynamic fog and ambient light curves properly.
Animation Curves give you full control over:
Instead of fixed logic, you design lighting visually in the Inspector.
Make sure fog is enabled before running the script.
Create a new script called DynamicEnvironmentController.cs.
using UnityEngine;
public class DynamicEnvironmentController : MonoBehaviour
{
[Header("Time Settings")]
public float dayDuration = 120f;
private float timeOfDay = 0f;
[Header("Sun")]
public Light sun;
[Header("Ambient Light Curve")]
public AnimationCurve ambientIntensityCurve;
[Header("Fog Settings")]
public AnimationCurve fogDensityCurve;
public Gradient fogColorGradient;
void Update()
{
UpdateTime();
UpdateSun();
UpdateAmbientLight();
UpdateFog();
}
void UpdateTime()
{
timeOfDay += Time.deltaTime / dayDuration;
if (timeOfDay > 1f)
timeOfDay = 0f;
}
void UpdateSun()
{
if (sun != null)
{
sun.transform.localRotation =
Quaternion.Euler((timeOfDay * 360f) - 90f, 170f, 0f);
}
}
void UpdateAmbientLight()
{
float intensity = ambientIntensityCurve.Evaluate(timeOfDay);
RenderSettings.ambientIntensity = intensity;
}
void UpdateFog()
{
RenderSettings.fogDensity = fogDensityCurve.Evaluate(timeOfDay);
RenderSettings.fogColor = fogColorGradient.Evaluate(timeOfDay);
}
}
After attaching the script to an empty GameObject:
Example curve design:
You control the shape visually instead of writing complex code.
The Gradient field lets you blend fog color smoothly.
Example gradient design:
This creates realistic atmospheric color transitions.
For most outdoor scenes, Exponential fog gives better results.
These updates are inexpensive compared to shadows or post-processing.
You can also replace fixed sun intensity with a curve:
[Header("Sun Intensity")]
public AnimationCurve sunIntensityCurve;
void UpdateSun()
{
if (sun != null)
{
sun.transform.localRotation =
Quaternion.Euler((timeOfDay * 360f) - 90f, 170f, 0f);
sun.intensity = sunIntensityCurve.Evaluate(timeOfDay);
}
}
This gives full artistic control over brightness transitions.
Dynamic fog and ambient light curves transform a basic day-night cycle into a believable atmosphere system. Animation Curves allow smooth, artistic transitions without complicated logic.
Instead of reacting to time with rigid code, you design lighting visually and let Unity interpolate smoothly throughout the day.
Once implemented correctly, your world will feel alive — with soft mornings, bright midday light, warm sunsets, and deep atmospheric nights.