U
tab 04World & Game Loop7 lessons — tap to open
02 / 07 · 10 min
World & Game Loop

Lighting and skybox

your project so far

Assets/

Scenes/

Arena.unity

TerrainMixed Directional Light

Scripts/

DayNight.cs

Project settings

baked lightmapsskybox + fog

you already havethis lesson adds

Your terrain is lit by the same Directional Light you rotated back in tab 01. The Knight standing on it has no shadow worth looking at. Both of those get fixed here.

Lighting decides how your game feels more than any model does. And one Directional Light drives most of it.

animated diagram

Rotate the sun and the whole mood, shadow direction and sky colour change with it.

The three light types you will use

  • Directional — the sun. Position is irrelevant, only rotation matters. One per scene.

  • Point — a bulb, radiating in all directions. Torches, lamps, magic orbs.

  • Spot — a cone. Flashlights, street lights, stage lighting.

Good default sun settings

  1. 1

    Rotation 50, -30, 0 — high enough to light faces, angled enough to cast readable shadows.

  2. 2

    Intensity around 1.0–1.3, colour a very slightly warm white (#FFF4E0).

  3. 3

    Shadow Type = Soft Shadows, Strength around 0.8. Pure black shadows look like a bug.

Realtime vs baked

✖ Realtime

Correct for anything that moves, expensive for everything that does not.

✓ Baked lightmaps

Computed once in the editor, free at runtime. This is how mobile games look good.
  1. 1

    Select every object that never moves and tick Static in the top-right of the Inspector. The Knight is NOT static — leave it alone.

  2. 2

    Set the Directional Light's Mode to Mixed: it bakes onto static objects and still lights the moving player.

  3. 3

    Open Window▸Rendering▸Lighting and press Generate Lighting.

  4. 4

    Start with Lightmap Resolution 10 while iterating. Raise it to 30–40 only for the final bake.

Skybox, ambient and fog

  • The skybox is not just a backdrop — it is the main source of ambient light on every surface.

  • In Lighting > Environment, Ambient Source = Skybox with Intensity 0.8–1.0 gives natural fill light in the shadows.

  • Fog hides the far clipping plane and lets you shrink the camera's Far distance — which is free performance.

  • Match the fog colour to the horizon colour of your skybox or the seam is obvious.

A day-night cycle in 12 lines

DayNight.cs — attach to the Directional Light
using UnityEngine;

public class DayNight : MonoBehaviour
{
    [SerializeField] private float dayLengthMinutes = 4f;
    [SerializeField] private Gradient sunColor;          // paint dawn → noon → dusk
    [SerializeField] private AnimationCurve intensity;

    private Light sun;
    private float t;                                     // 0 .. 1 across a full day

    void Awake() => sun = GetComponent<Light>();

    void Update()
    {
        t += Time.deltaTime / (dayLengthMinutes * 60f);
        t %= 1f;

        transform.rotation = Quaternion.Euler((t * 360f) - 90f, 30f, 0f);
        sun.color = sunColor.Evaluate(t);
        sun.intensity = intensity.Evaluate(t);

        RenderSettings.ambientIntensity = Mathf.Lerp(0.2f, 1f, sun.intensity);
    }
}