chocolate.gd 746 B

123456789101112131415161718192021222324252627282930313233
  1. class_name Chocolate
  2. extends Node3D
  3. const COLLECT_ANIM := "collection"
  4. @onready var chocolateAnimation: AnimationPlayer = $ChocolateAnimation
  5. @onready var pickupSound: AudioStreamPlayer3D = $ChocolatePickupSound
  6. var _collected := false
  7. func _on_chocolate_tablet_body_entered(body: Node3D) -> void:
  8. if _collected:
  9. return
  10. if body is Walker:
  11. _give_chocolate_to(body)
  12. _collected = true
  13. func _give_chocolate_to(walker: Walker) -> void:
  14. walker.give_chocolate()
  15. reparent.call_deferred(walker)
  16. chocolateAnimation.play(COLLECT_ANIM)
  17. chocolateAnimation.animation_finished.connect(_finish)
  18. pickupSound.play()
  19. func _finish(animation_name: String) -> void:
  20. if COLLECT_ANIM == animation_name:
  21. # Collection is finished
  22. queue_free()