GAME 1303 — Tier 2: Enemies & Combat

Twelve scripts that sit on top of the Tier 1 kit. Requires Tier 1 (Health, PlayerController2D, PlayerAnimatorBridge, AudioManager) in the project.

Scripts/
  Combat/   Team (enum), Hurtbox, Hitbox, Knockback, ComboCounter,
            MeleeAttack, Projectile, ProjectileShooter
  Enemies/  EnemyPatrol, EnemyChase, FloatingEnemy, BossController, BossArenaTrigger

The one idea to teach first: Hurtbox vs Hitbox

Physics 2D layer setup (do this once): create layers Hitbox and Hurtbox. In Project Settings → Physics 2D → Layer Collision Matrix, untick everything for those two layers except Hitbox × Hurtbox. Now hit detection never interferes with movement collisions.

Recipes

Basic walking enemy (Magnet's criminals, Commission Witch ghosts on the ground)
Root: Sprite, Rigidbody2D (freeze Z), CapsuleCollider2D, Health (Destroy On Death ✓), Knockback, EnemyPatrol (Sensors mode with WallCheck/LedgeCheck children), Animator + PlayerAnimatorBridge (optional).
Children: Hurtbox (Team Enemy), Hitbox always-on (Target Player, damage 1, Repeat Delay 1).

Enemy that chases and punches (Missile Man thugs, Roach Invasion roaches)
Same as above + EnemyChase (Grounded) + MeleeAttack (Player Controlled OFF, with its own disabled Hitbox child). Wire EnemyChase.OnAttack → MeleeAttack.Attack.

Ghost (Detective Liz, Commission Witch, flying roach)
Rigidbody2D gravity 0. FloatingEnemy (Hover or Wander) + optional EnemyChase (Movement = Free, Line of Sight off). Hurtbox child. Touch damage via always-on Hitbox or DamageOnContact.

Turret / archer / sorcerer NPC
ProjectileShooter (Mode AutoFire, Aim TowardPlayer, Team Enemy) with a FirePoint child and a Projectile prefab (Rigidbody2D gravity 0, trigger collider, Blocking Layers = Ground).

Player melee (Stardust, Spark of Corruption, Magnet, MythoClash)
On the player root: MeleeAttack + Knockback + (Stardust) ComboCounter. Child "AttackHitbox" disabled with Hitbox (Target Enemy). Add Hurtbox child (Team Player). Wire AttackHitbox.OnHit → ComboCounter.RegisterHit and player Health.OnDamaged → ComboCounter.ResetCombo.

Player shooter (Stardust buster, sorcerer bolts)
ProjectileShooter on the player, Mode PlayerInput, Team Player. If the player also has MeleeAttack, both listen to "Attack" — set one of them to Manual and add a second action in the Input Actions asset (e.g. duplicate Attack as "Shoot", then call ProjectileShooter.Fire from an OnShoot message in a two-line script, or bind it with PlayerInput's Unity Events behavior).

Boss (Blaster, Zap Attack sector bosses, MythoClash monsters)
Root: Health (30+, invuln 0), Knockback (Resistance 1), BossController, plus whatever attack components you want (ProjectileShooter Manual, MeleeAttack non-player, hitbox children). In BossController, add phases at 100% and 50%, and in each phase's attack list wire On Execute to ProjectileShooter.Fire, MeleeAttack.Attack, or SomeHitbox.SetActive(true) (and a second attack entry that sets it false). Put a BossArenaTrigger at the room entrance with Start Automatically off.

Animator triggers used

Attack (MeleeAttack), Shoot (ProjectileShooter), plus whatever names you type into BossController attacks. Hurt and Dead come from Tier 1's bridge.

AudioManager sound names referenced

swing, shoot. Add clips with those names or change the field on the component.

Notes for the instructor