GAME 1303 — Tier 4: Hazards, Level Pieces & Progression

Eighteen scripts. No changes to earlier tiers this time — Tier 4 sits on top of Tier 1 (Health, DamageOnContact, CollectionTracker, AudioManager, SceneLoader, GameManager) and optionally Tier 2 (Hurtbox for breakables and hit-switches).

Requires the Tier 3 v1.1 update of DamageOnContact (the one that respects its enabled checkbox). Almost every hazard here works by switching damage on and off, and without that fix a retracted spike still kills you.

Scripts/
  Hazards/      SpinningSaw, SpikeTrap, Crusher, CyclingHazard, ElectricZone, KillZone
  Level/        Breakable, Door, PuzzleSwitch, SwitchGroup, LevelExit
  Progression/  ChoiceFlagManager, LevelData, LevelSet, LevelProgress,
                LevelTimer, LevelSelectButton, LevelSelectMenu

The pattern behind every hazard

A hazard is a trigger collider + DamageOnContact + a script that turns that component on and off on a schedule. Once students see that, they can build any trap in their pitch without new code:

Want Build
Always-deadly spikes / acid Trigger + DamageOnContact (Instant Kill). No hazard script needed.
Bottomless pit KillZone stretched under the level.
Timed flame jet CyclingHazard with On/Off times + a particle system.
Electric arc that stuns ElectricZone (a CyclingHazard subclass — flicker + input stun).
Pop-up spikes SpikeTrap, Timed or Triggered.
Ceiling shock ("jump too high") ElectricZone, Always On, wide thin trigger along the top.
Slamming piston Crusher (auto-measures its drop with a raycast).
Saw blade SpinningSaw; add Tier 1 MovingPlatform to make it patrol.

Every timed hazard has a Warning Time with a shake or a warning sprite. That's the fairness rule worth stating in class: a trap the player couldn't have anticipated isn't difficulty, it's a coin flip. Nicholas's course lives or dies on this.

Doors, switches and gates

Progression (Zap Attack and MythoClash mainly)

LevelData (one asset per level) and LevelSet (one per sector/world) are ScriptableObjects; LevelProgress is a static PlayerPrefs helper — no component to place. A level unlocks when it's marked unlocked-from-start, was purchased, or its prerequisites are cleared (default: the previous level in the set). TryPurchase spends currency from the CollectionTracker, which is exactly Tony's green-electricity generator door at the level-select scale.

LevelTimer counts up (speedrun) or down (a limit), formats as mm:ss.hh, and saves the best time per level id. Wire LevelExit.OnCompleted → LevelTimer.StopAndRecord.

LevelSelectMenu + LevelSelectButton build the grid from a LevelSet and show locked / cleared / best-time state.

Warn students about Level Id: progress saves under that string, so renaming one after playtesting silently resets it. And PlayerPrefs persists across rebuilds and is shared per-project on a machine — that's the usual answer to "why is level 3 still unlocked?" LevelProgress.ResetAll() is wired into LevelSelectMenu.ResetAllProgress for a clear-save button.

Per-game recipes

AudioManager names referenced

spike_warn, spike_pop, crusher_slam, zap, fall, break, thud, door_open, door_locked, switch_on, level_complete.

Notes for the instructor