44 lines
914 B
GDScript
44 lines
914 B
GDScript
extends Node3D
|
|
class_name SpawnTube
|
|
|
|
@export var level_bounds : LevelBounds
|
|
@export var switch : SwitchBasic
|
|
|
|
var open = true
|
|
var active = true
|
|
|
|
@onready var anim_player: AnimationPlayer = $AnimationPlayer
|
|
|
|
|
|
func _on_player_detect_body_entered(body: Node3D) -> void:
|
|
if body is Player:
|
|
if open and active:
|
|
anim_player.play("close")
|
|
open = false
|
|
|
|
if body is Chest:
|
|
if !body.claimed:
|
|
body.claimed = true
|
|
var old_pos = body.global_position
|
|
body.get_parent().remove_child(body)
|
|
get_tree().current_scene.add_child(body)
|
|
body.global_position = old_pos
|
|
|
|
|
|
|
|
func _on_player_detect_body_exited(body: Node3D) -> void:
|
|
if body is Player:
|
|
SignalBus.emit_signal("player_left_tube")
|
|
|
|
|
|
func _on_switch_1_switch_changed() -> void:
|
|
if open:
|
|
anim_player.play("close")
|
|
open = false
|
|
else:
|
|
anim_player.play("open")
|
|
open = true
|
|
|
|
if level_bounds != null:
|
|
level_bounds.toggle_collision(!open)
|