1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 17:14:20 +00:00
swear-jar/interface/ghost/instantiator.gd

27 lines
677 B
GDScript

extends Node
class_name Instantiator
## The [PackedScene] that this node should instantiate.
@export var scene_to_instantiate: PackedScene
## The [Node] instantiated scenes should be attached to.
@export var container: Node
## The [Node2D] instantiated scenes should get properties from.
@onready var target: Node2D = get_parent()
func instantiate():
var inst = scene_to_instantiate.instantiate()
inst.global_position = target.global_position
inst.rotation = target.rotation
container.add_child(inst)
instantiated.emit(inst)
# TODO: Remove this
return inst
## Emitted when the [instantiate] function has finished executing.
signal instantiated(new_scene: Node)