← Back to games

Tower Defense 2D

Mouse-aimed 2D defense shooter built on pooled projectiles and singleton managers

Unity 2021.3 LTSC#Object PoolSingletonTemplate MethodRigidbody2D
Tower Defense 2D

A 2D defense shooter: aim with the mouse, click to fire, and clear waves of enemies before they breach your base. Built as a study in keeping runtime allocations at zero and gameplay systems decoupled.

Tech stack

Unity 2021.3 LTS · C# · Unity 2D physics (Rigidbody2D, collision callbacks) · uGUI · PlayerPrefs persistence

Architecture & design patterns

  • Object Pool — BulletPool pre-instantiates separate player and enemy bullet lists on startup and hands out deactivated instances via getBullets(BulletType), so combat never calls Instantiate or Destroy
  • Singleton — GameManager, EnemySpawner, BulletPool, SoundManager and PlayerController each guard a static Instance in Awake(), destroying duplicates to keep a single authority per system
  • Template Method via inheritance — EnemyController extends GunController and overrides a virtual Aim(), reusing the shared fire/spawn pipeline while swapping mouse aiming for AI targeting
  • Enum-keyed lookup tables — BulletType selects the pool to draw from, and a serialized SoundType[] maps SoundEvents to AudioClips, so audio is triggered by intent rather than direct references
  • State-driven progression — a Level[] model carries LevelStatus (locked / unlocked / completed) and scales enemy count per level, with high scores persisted through PlayerPrefs

Aiming uses ScreenToWorldPoint clamped to a maximum angle, with projectiles driven by physics impulses.