Files
AceField-New-Horizon/Scripts/Tiles/EnemyNestTile.cs
2025-08-30 02:06:58 +08:00

35 lines
878 B
C#

using Godot;
namespace AceFieldNewHorizon.Scripts.Tiles;
public partial class EnemyNestTile : BaseTile
{
[Export] public PackedScene EnemyScene;
private Timer _spawnTimer;
public override void _Ready()
{
base._Ready();
// Create and configure the timer
_spawnTimer = new Timer();
AddChild(_spawnTimer);
_spawnTimer.Timeout += OnSpawnTimerTimeout;
_spawnTimer.Start(1.0f); // Start with 1 second interval
}
private void OnSpawnTimerTimeout()
{
if (EnemyScene != null)
{
var enemy = EnemyScene.Instantiate();
GetParent().AddChild(enemy);
// Position the enemy at the nest's position
if (enemy is Node2D enemy2D)
{
enemy2D.GlobalPosition = GlobalPosition;
}
}
}
}