Files
godot-action-adventure-test/Scenes/TreasureChest/treasure_chest.gd
T

24 lines
549 B
GDScript

extends StaticBody2D
var can_interact: bool = false
var is_open: bool = false
@export var scrolls: Array[Sprite2D]
var scroll_number = 0
func _ready() -> void:
scroll_number = randi_range(1, 4)
func _process(delta: float) -> void:
if Input.is_action_just_pressed("Interact") and can_interact:
if !is_open:
$AudioStreamPlayer.play()
$AnimatedSprite2D.play("open")
scrolls[scroll_number].visible = true
$Timer.start()
is_open = true
func _on_timer_timeout(scroll_number: int) -> void:
scrolls[scroll_number].visible = false