save
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class EnemySpawner : Node
|
||||
{
|
||||
[Export] private Node _pathParent;
|
||||
[Export] private EnemyPool _pool;
|
||||
|
||||
private readonly List<Path2D> _paths = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user