extends StaticBody2D
signal chest_opened
var keytaken = false
var inchestzone = false
warning-ignore:unusedargument
func _onArea2Dbodyentered(body: PhysicsBody2D): #area2d - > key
if keytaken == false:
keytaken = true
$Sprite.queuefree()
warning-ignore:unusedargument
func process(delta):
if keytaken == true:
if inchestzone == true:
emitsignal("chest_opened")
warning-ignore:unusedargument
func _onchestzonebodyentered(body: PhysicsBody2D): #chest zone -> key
inchest_zone = true
extends StaticBody2D
onready var only_once : bool = true
onready var animationplayer = $AnimationPlayer
func _ready():
animationplayer.play("Idle")
func onKeychestopened():
if onlyonce == true:
animationplayer.play("Open")
onlyonce = false
If the player enters the chest's zone before having the key, the chest stays locked.
Although, as soon as the player obtains the key, the chest instantly opens.
Can anyone help me come up with a solution for this issue?
Thanks in advance!