One vs Many

This article explores rebuilding a “One vs Many” style game using Unity’s Entity Component System (ECS). ECS enables spawning thousands of enemies while maintaining strong CPU performance—ideal for games where a single player faces numerous adversaries.

Core Entity Components

The game uses three main entity types defined through component data structures:

Player, Bullet, and Enemy Components:

  • Players track score
  • Enemies have point values
  • Bullets maintain active status and age tracking

Movement and Health Systems: The implementation uses shared components for movement (direction and speed) and health tracking using integer or float values. Damage components handle collision effects.

Implementation Details

Player Input System

Players control movement via keyboard or gamepad input. The system processes horizontal and vertical axes, normalizes direction vectors, and applies health degeneration over time. Bullet firing occurs through left-mouse-click detection, where inactive bullets get reactivated at the player’s position and directed toward the clicked location.

Bullet Movement

A dedicated movement system handles bullet trajectory. Bullets travel along their assigned direction at specified speeds, with automatic deactivation after three seconds. Inactive bullets are repositioned off-screen.

Enemy Spawning

Enemies spawn through entity creation in pure code (without prefabs), receiving movement, health, rendering, and collision components. A coroutine manages spawn intervals.

Challenges and Extensions

Suggested improvements include: implementing linear enemy movement toward players, preventing enemy clustering through flocking algorithms, and adding collectible health items.

Source Code

Full implementation available on my GitHub repository.