33 lines
658 B
GDScript3
33 lines
658 B
GDScript3
|
@tool
|
||
|
extends Composer
|
||
|
class_name Spawner
|
||
|
|
||
|
@export var unit_type: PackedScene
|
||
|
@export var spawn_duration = 1.0
|
||
|
var _spawning_since = 0.0
|
||
|
|
||
|
@export var delivery = Vector2(100.0, 0.0):
|
||
|
set(val):
|
||
|
delivery = val
|
||
|
_check_compose()
|
||
|
|
||
|
func _compose():
|
||
|
$delivery.position = delivery
|
||
|
|
||
|
func _physics_process(delta):
|
||
|
if Engine.is_editor_hint():
|
||
|
return
|
||
|
|
||
|
_spawning_since += delta
|
||
|
if _spawning_since > spawn_duration:
|
||
|
spawn()
|
||
|
|
||
|
func spawn():
|
||
|
if unit_type:
|
||
|
var unit := unit_type.instantiate()
|
||
|
if unit is Unit:
|
||
|
unit.position = delivery
|
||
|
_spawning_since = min(0.0, _spawning_since - spawn_duration)
|
||
|
# FIXME add to battlefield
|
||
|
add_child(unit)
|