Godot Version
4.4
Question
I’m working on a pause menu. I want to be able to pause the game using a pause button and the escape key. The buttons work as intended and I have already mapped the escape key. When the menu is opened using the pause button I can use the escape key to close the menu however I cannot use the escape key to open the menu. Can someone please point me in the right direction? My script code is listed below:
extends Control
Called when the node enters the scene tree for the first time.
func _ready() → void:
pass # Replace with function body.
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta: float) → void:
pass
#function to toggle the pause menu/pause the game
func toggle_pause():
if get_tree().paused:
get_tree().paused = false
hide()
else:
get_tree().paused = true
show()
func _input(event: InputEvent) → void:
if Input.is_action_pressed(“pause”):
toggle_pause()
#Shows the pause menu when the pause button is pressed
func _on_pause_button_pressed() → void:
toggle_pause()
#hides the pause menu when the continue button is pressed
func _on_continue_pressed() → void:
toggle_pause()
#returns to start menu when leave game button is pressed
func _on_leave_game_pressed() → void:
get_tree().paused = false
get_tree().change_scene_to_file(“res://screens/ui/Menu.tscn”)
#exits the game
func _on_exit_pressed() → void:
get_tree().quit()