Files
godot-action-adventure-test/Scenes/PuzzleButton/puzzle_button.gd
T

20 lines
563 B
GDScript

extends Area2D
var bodies_on_top = 0
signal pressed
signal unpressed
@export var is_single_use: bool = false
func _on_body_entered(body: Node2D) -> void:
bodies_on_top = bodies_on_top + 1
if (body.is_in_group("pushable") or body is Player) and bodies_on_top == 1:
$AnimatedSprite2D.play("pressed")
pressed.emit()
func _on_body_exited(body: Node2D) -> void:
if is_single_use:
return
bodies_on_top = bodies_on_top - 1
if (body.is_in_group("pushable") or body is Player) and bodies_on_top == 0:
$AnimatedSprite2D.play("unpressed")
unpressed.emit()