In our earlier tutorial we learned how to move an object in Godot. In this tutorial, we will create a button to increase the speed of the object.
What you will learn
- Creating a new button.
- Adding text to the button
- Linking the button to the object script.
Let’s get started
Creating a new Button
- Click on the + sign in the scene window.
- Seach for the button node.
- Click create to add a button to the scene.
Changing Button properties
- Select the button node and go to the inspector window.
- You can enter the text that you want to see on the button in the text field.
- If you have a design ready for the button you can add it to the icon.
- In the Rect properties you can change the size and position of the button.
Linking the button press action to script
- Select the button node.
- Go to node window near the inspector.
- You should see many signals. Double click on the pressed () signal in the BaseButton category.
- This will open a window. Select the node you want to link with the button. The node should have a script attached to it. You can change the function name to your liking in the Receiver Method dialog box.
- This will create a new function in the script.
- Add your required script. In our case it’s a simple line.
func _on_Button_pressed():
speed+=10
Now play the game and click on the button to increase the player speed by 10. If you have any questions, leave it in the comment section below.