61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_duplicate.png")]
|
|
public partial class Spawner : Node3D
|
|
{
|
|
[Export(PropertyHint.NodeType)]
|
|
public PackedScene EnemyToSpawn { get; set; }
|
|
|
|
[Export]
|
|
public RMovement MovementInputs { get; set; }
|
|
[Export]
|
|
public RHealth HealthInputs { get; set; }
|
|
[Export]
|
|
public RDamage DamageInputs { get; set; }
|
|
|
|
[Export]
|
|
public Node3D Target { get; set; }
|
|
|
|
[Export(PropertyHint.Range, "0.1, 100, 0.1, or_greater")]
|
|
public float SpawnInterval { get; set; } = 1.0f;
|
|
[Export]
|
|
public bool IsActiveOnStart { get; set; } = true;
|
|
|
|
private Timer _timer;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_timer = GetNode<Timer>("Timer");
|
|
_timer.WaitTime = SpawnInterval;
|
|
_timer.Timeout += Spawn;
|
|
if (IsActiveOnStart) StartSpawning();
|
|
}
|
|
|
|
public void Spawn()
|
|
{
|
|
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();
|
|
}
|
|
|
|
public void StartSpawning()
|
|
{
|
|
_timer.Start();
|
|
}
|
|
|
|
public void StopSpawning()
|
|
{
|
|
_timer.Stop();
|
|
}
|
|
}
|