43 lines
1.2 KiB
GDScript
43 lines
1.2 KiB
GDScript
class_name MapChangeInteract extends Node3D
|
|
|
|
var interactableArea:InteractableArea
|
|
var shapeChild:CollisionShape3D
|
|
|
|
func _enter_tree() -> void:
|
|
interactableArea = $InteractableArea
|
|
|
|
# Needs to be exactly one child.
|
|
if get_child_count() != 2:
|
|
push_error("MapChangeInteract must have exactly one child InteractableArea node.")
|
|
return
|
|
|
|
var child = get_child(1)
|
|
if not (child is CollisionShape3D):
|
|
push_error("MapChangeInteract's child must be an CollisionShape3D node.")
|
|
|
|
shapeChild = child
|
|
remove_child(shapeChild)
|
|
interactableArea.add_child(shapeChild)
|
|
|
|
interactableArea.interactEvent.connect(onInteract)
|
|
interactableArea.interactable.connect(onInteractable)
|
|
interactableArea.notInteractable.connect(onNotInteractable)
|
|
|
|
func _exit_tree() -> void:
|
|
interactableArea.interactEvent.disconnect(onInteract)
|
|
interactableArea.interactable.disconnect(onInteractable)
|
|
interactableArea.notInteractable.disconnect(onNotInteractable)
|
|
|
|
interactableArea.remove_child(shapeChild)
|
|
add_child(shapeChild)
|
|
|
|
func onInteract(ent:Player) -> void:
|
|
print("MapChangeInteract: onInteract called")
|
|
|
|
func onInteractable(ent:Player) -> void:
|
|
print("Able to leave map")
|
|
pass
|
|
|
|
func onNotInteractable(ent:Player) -> void:
|
|
print("Not able to leave map")
|
|
pass |