I’ve created spawn points that the enemy waves generate from.
public GameObject enemyPrefab;
public float spawnInterval = 2f; // Seconds between spawns
public int maxEnemies = 10; // Limit how many can exist at once
private float timer = 0f;
private int spawnedCount = 0;
void Update()
{
// Count up time
timer += Time.deltaTime;
// If enough time passed and we haven’t reached max enemies, spawn one
if (timer >= spawnInterval && spawnedCount < maxEnemies)
{
SpawnEnemy();
timer = 0f;
}
}
void SpawnEnemy()
{
// Spawn at the spawner’s position
Vector3 spawnPos = new Vector3(transform.position.x, transform.position.y, 0f);
Instantiate(enemyPrefab, spawnPos, Quaternion.identity);
spawnedCount++;
}
}