chocolate.gd 642 B

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