How to make a texture button switch scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pranav

I’m making a FNaF styled-game in Godot. I have the New Game button on the main menu which is a TextureButton. It changes animation when hovered, but how do I make it so that it switches scenes on clicking the button? Thanks.

:bust_in_silhouette: Reply From: Diet Estus

Buttons and TextureButtons emit the pressed() signal when they are pressed. For a brief overview of signals, see the documentation.

You want to link this signal to some change scene code so that when the button is pressed, the change scene code is executed.

To do this, click on your Button node, then select the Node tab beside the Inspector tab. Then select the pressed() signal. This will open a window to select which node you want to connect the signal to. Select whatever main node is running the main script of your scene.

For example,

Then you can write whatever change scene code you want to be executed.

For example,


Thanks, You are the best!

Pranav | 2018-04-10 06:25