pause_button.gd 528 B

123456789101112131415161718
  1. extends Button
  2. func _ready():
  3. # This ensures that this Node won't be paused, allowing it to
  4. # process even when the SceneTree is paused. Without that it would
  5. # not be able to unpause the game. Note that you can set this through
  6. # the inspector as well.
  7. process_mode = Node.PROCESS_MODE_ALWAYS
  8. func _toggled(is_button_pressed):
  9. # Pause or unpause the SceneTree based on whether the button is
  10. # toggled on or off.
  11. get_tree().paused = is_button_pressed
  12. if is_button_pressed:
  13. text = "Unpause"
  14. else:
  15. text = "Pause"