Files

34 lines
626 B
GDScript

extends RigidBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
@export var hit_object:PackedScene
@export var auto_collect:bool
var destroyed = false
var instance = null
var _body = null
@onready var timer = $Timer
func _ready():
animated_sprite_2d.play("idle")#
func _on_activate_body_entered(body):
_body = body
if destroyed:
return
destroyed = true
animated_sprite_2d.play("destroy")
if hit_object == null:
return
instance = hit_object.instantiate()
add_child(instance)
instance.position.y -= 16
timer.start()
func _on_timer_timeout():
if auto_collect:
instance.collect_coin(_body)