In my game, I start the gameplay after clicking the left mouse button:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed :
if game_running == false:
start_game()
But I would like to add a mute button to the main screen. But when you add such a button, when you click on it, the gameplay begins. How can I make this?
how to add a button in screen in Godot 4?
- Edited
Scel if event is InputEventMouseButton:
Try moving that to _unhandled_input.
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
...
Or don't start the game if the mouse click is inside the mute button: button.get_global_rect().has_point(event.position)
.
DaveTheCoder Yes, I was thinking of using func _unhandled_input(event: InputEvent) -> void, but I can't start the gameplay properly because of this part of the script. I wrote my project based on a tutorial from Youtube( ). I hope this will help in solving my problem.
Scel You could also, you know, just make a button for starting the game - or listen to an input event that isn't the left mouse button so you don't have conflicts.