1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 08:04:23 +00:00
hella-farm/behaviours/spawner.gd

21 lines
513 B
GDScript3
Raw Normal View History

2024-04-16 01:02:19 +00:00
@icon("res://behaviours/spawner.svg")
2024-04-19 01:47:34 +00:00
extends Area2D
2024-04-14 17:48:13 +00:00
class_name Spawner
signal spawned(entity: Node2D)
@export var scene: PackedScene
2024-04-19 01:47:34 +00:00
@export var target: Node2D
2024-04-14 17:48:13 +00:00
2024-04-16 01:02:19 +00:00
2024-04-19 01:47:34 +00:00
func spawn():
2024-04-16 01:02:19 +00:00
if not target:
target = MainGame.get_ancestor(self).default_spawn_parent
if not target:
target = self
2024-04-14 17:48:13 +00:00
var entity = scene.instantiate()
entity.global_scale = global_scale
entity.global_position = global_position
entity.global_rotation = global_rotation
2024-04-16 01:02:19 +00:00
target.add_child.call_deferred(entity) # Not sure why this is needed.