Creating a simple button
A UI is a collection of components you lay out in a coherent manner around the core visuals of your game. The most essential UI component to start with may have been a Label node if we wanted it to be similar to printing “Hello, world!” when we are learning a new programming language. However, we’ll start with a Button node since the former case is so trivial, and we can also learn how to style a Button during this effort.
Before we start throwing around a bunch of UI nodes willy-nilly, we should first mention the right kind of structure to hold our UI nodes. We can use CanvasLayer similar to using a Spatial node to nest other nodes such as MeshInstance, AnimationPlayer, and others.
We’ve already been creating scenes mainly to display 3D models. Let’s follow similar steps for the sake of creating the UI:
- Create a blank scene and save it as
UI.tscn
in theScenes
folder. - Choose CanvasLayer for its root node...