Horde & Wave Logic
Overview
Manages the pacing and spawning of enemy units. Uses ScriptableObjects to define wave configurations, allowing designers to tweak difficulty without touching code.
When to Use
- Use for Tower Defense games
- Use for "Horde Mode" survival
- Use for timed enemy assaults
- Use for testing combat balance
- Use for creating "Boss Waves"
Architecture
┌─────────────────────────────────────────────────────────────┐
│ WAVE CONTROLLER │
├─────────────────────────────────────────────────────────────┤
│ │
│ WAVE CONFIG (Asset) SPAWNER (MonoBehaviour) │
│ ┌────────────────┐ ┌───────────────────────────┐ │
│ │ Wave 1: │ │ State: Waiting/Spawning │ │
│ │ - 10 Zombies │─────▶│ Timer: 30s │ │
│ │ - Rate: 0.5s │ │ Coroutine: SpawnLoop() │ │
│ └────────────────┘ └─────────────┬─────────────┘ │
│ │ │
│ ▼ │
│ OBJECT POOL ┌───────────────────────────┐ │
│ ┌────────────────┐ │ Instantiate / GetFromPool │ │
│ │ Zombie Prefab │◀──────│ Set Position (SpawnPoint) │ │
│ └────────────────┘ └───────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Best Practices
- ✅ Use Object Pooling for enemies (Critical for performance).
- ✅ Define Waves as
ScriptableObjects(List of Waves). - ✅ Include "Warmup" time between waves.
- ✅ Support multiple Spawn Points.
- ✅ Implement "Wave Cleared" logic (Track active enemy count).
- ❌ NEVER Instantiate enemies during the loop without pooling.
- ❌ NEVER use
InvokeRepeating(hard to control); use Coroutines.
Few-Shot Examples
Example 1: Wave Config Data
User: "Create data for a wave."
Agent:
[CreateAssetMenu]
public class WaveData : ScriptableObject
{
public GameObject EnemyPrefab;
public int Count;
public float SpawnRate;
}
Example 2: Spawner Logic
User: "Spawn the wave."
Agent:
IEnumerator SpawnWave(WaveData wave)
{
for (int i = 0; i < wave.Count; i++)
{
SpawnEnemy(wave.EnemyPrefab);
yield return new WaitForSeconds(wave.SpawnRate);
}
}
TDD Contract
⚠️ Legacy Skill — Refactor Pending
Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.
// Escribe estos tests ANTES de implementar:
// Test 1: should [expected behavior] when [condition]
[Test]
public void HordeWaveLogic_Should{ExpectedBehavior}_When{Condition}()
{{
// Arrange
// TODO: Setup test fixtures
// Act
// TODO: Execute system under test
// Assert
Assert.Fail("Not implemented — write test first");
}}
// Test 2: should handle [edge case]
[Test]
public void HordeWaveLogic_ShouldHandle{EdgeCase}()
{{
// Arrange
// TODO: Setup edge case scenario
// Act
// TODO: Execute
// Assert
Assert.Fail("Not implemented");
}}
// Test 3: should throw when [invalid input]
[Test]
public void HordeWaveLogic_ShouldThrow_When{InvalidInput}()
{{
// Arrange
var invalidInput = default;
// Act & Assert
Assert.Throws<Exception>(() => {{ /* execute */ }});
}}
Pasos para completar el TDD:
- Descomenta los tests above
- Implementa la funcionalidad mínima para que compile
- Ejecuta los tests — deben fallar (RED)
- Implementa la funcionalidad real
- Verifica que los tests pasen (GREEN)
- Refactorea manteniendo los tests verdes
Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.
Related Skills
@object-pooling-system- Required for spawner@unit-population-ai- AI for spawned units@unity-events-messaging- "Wave Start/End" events