using Godot; using System.Collections.Generic; public partial class EnemySpawner : Node { public static EnemySpawner Instance; [Export] private Node _pathParent; [Export] private EnemyPool _pool; private readonly List _paths = new(); public int EnemiesSpawned = 0; public override void _Ready() { Instance = this; foreach (var c in _pathParent.GetChildren()) if (c is Path2D p) _paths.Add(p); // for (int i = 0; i < 10; i++) // SpawnWithDelay(i * 0.33f); } public async void SpawnWithDelay(float t) { await ToSignal(GetTree().CreateTimer(t), SceneTreeTimer.SignalName.Timeout); Spawn(); } private void Spawn() { if (_paths.Count == 0) return; var path = _paths[GD.RandRange(0, _paths.Count - 1)]; var type = _pool.GetRandomType(); var enemy = _pool.Get(type); if (enemy == null) return; path.AddChild(enemy); } }