fixed spawners
This commit is contained in:
@@ -22,21 +22,14 @@ public partial class Spawner : Node3D
|
||||
[Export]
|
||||
public bool IsActiveOnStart { get; set; } = true;
|
||||
|
||||
private float _spawnTimer;
|
||||
private bool _isActive;
|
||||
private Timer _timer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_isActive = IsActiveOnStart;
|
||||
_spawnTimer = SpawnInterval;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_isActive) return;
|
||||
|
||||
_spawnTimer -= (float) delta;
|
||||
if (_spawnTimer <= 0) Spawn();
|
||||
_timer = GetNode<Timer>("Timer");
|
||||
_timer.WaitTime = SpawnInterval;
|
||||
_timer.Timeout += Spawn;
|
||||
if (IsActiveOnStart) StartSpawning();
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
@@ -44,27 +37,24 @@ public partial class Spawner : Node3D
|
||||
if (EnemyToSpawn == null || !EnemyToSpawn.CanInstantiate()) return;
|
||||
|
||||
if (EnemyToSpawn.Instantiate() is not Enemy spawnedInstance) return;
|
||||
|
||||
|
||||
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||
|
||||
spawnedInstance.Target = Target;
|
||||
spawnedInstance.RMovement = MovementInputs;
|
||||
spawnedInstance.RDamage = DamageInputs;
|
||||
spawnedInstance.RHealth = HealthInputs;
|
||||
spawnedInstance.Initialize();
|
||||
|
||||
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||
|
||||
_spawnTimer = SpawnInterval;
|
||||
}
|
||||
|
||||
public void StartSpawning()
|
||||
{
|
||||
_isActive = true;
|
||||
_spawnTimer = SpawnInterval;
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
public void StopSpawning()
|
||||
{
|
||||
_isActive = false;
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@
|
||||
script = ExtResource("1_2otbo")
|
||||
|
||||
[node name="Marker3D" type="Marker3D" parent="." unique_id=610854505]
|
||||
|
||||
[node name="Timer" type="Timer" parent="." unique_id=1842357493]
|
||||
|
||||
Reference in New Issue
Block a user