diff options
Diffstat (limited to 'Scenes/Components/Teleport.gd')
-rw-r--r-- | Scenes/Components/Teleport.gd | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Scenes/Components/Teleport.gd b/Scenes/Components/Teleport.gd new file mode 100644 index 0000000..03e900f --- /dev/null +++ b/Scenes/Components/Teleport.gd @@ -0,0 +1,26 @@ +extends Node2D + +class_name Teleport + +@export_node_path("Teleport") var target: NodePath + +var targetNode: Teleport + +# Called when the node enters the scene tree for the first time. +func _ready(): + self.targetNode = get_node(self.target) + + self.targetNode.get_node("Leave").connect("body_exited", _on_body_exited) + + +func _on_body_entered(body): + if body is Player: + var player: Player = body + + (func(): self.targetNode.get_node("Enter/CollisionShape2D").disabled = true).call_deferred() + player.position = self.targetNode.position + + +func _on_body_exited(body): + if body is Player: + (func(): targetNode.get_node("Enter/CollisionShape2D").disabled = false).call_deferred() |