- Select manual -
A GUI box node with an image texture and a script to make it act as a button.
The “gui” game object contains a GUI component stored in the file button.gui. The GUI contains the setup with the “button” box node for the button image and the “text” text node for the button label text.
button.gui has a script attached to it, called button.gui_script, which contains the button logic.
function init(self) msg.post(".", "acquire_input_focus") end function on_input(self, action_id, action) if action_id == hash("click") and action.pressed then local button = gui.get_node("button") local text = gui.get_node("text") if gui.pick_node(button, action.x, action.y) then gui.set_text(text, "HELLO!") else gui.set_text(text, "CLICK ME!") end end end
- Tell the engine that this game object wants to receive input.
- If the user clicks.
- Get the instance for the node named “button” (the button box).
- Get the instance for the node named “text” (the button label).
- Check if the click position (
action.y) is within the boundaries of the button node.
- If the user clicks on the button, change the label text.
- If the user clicks elsewhere, change the label text to something else.
If you want to play with these examples, you can get the project on Github.
Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.