pause_button.gd 550 B

12345678910111213141516171819
  1. extends Button
  2. func _ready() -> void:
  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: bool) -> void:
  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"