22 lines
634 B
GDScript
22 lines
634 B
GDScript
extends Node
|
|
|
|
const GATE_SCENE: PackedScene = preload("res://scenes/portal/gate.tscn")
|
|
|
|
func _ready() -> void:
|
|
EventBus.entity_died.connect(_on_entity_died)
|
|
|
|
func _on_entity_died(entity: Node) -> void:
|
|
if not entity.is_in_group("portals"):
|
|
return
|
|
if not entity.is_inside_tree():
|
|
return
|
|
var pos: Vector3 = entity.global_position
|
|
var gate: Node3D = GATE_SCENE.instantiate()
|
|
entity.get_parent().add_child(gate)
|
|
gate.global_position = pos
|
|
for enemy in get_tree().get_nodes_in_group("enemies"):
|
|
if is_instance_valid(enemy):
|
|
enemy.queue_free()
|
|
EventBus.portal_defeated.emit(entity)
|
|
entity.queue_free()
|