how to use a button for two different outcome ??

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

hey i want to build a character selection ui so i created a button and link it to a texture rect node when pressed it load another character but i don’t know how to make it go back to the original character

My code:
func _on_nextcharacterButton_pressed():
$TextureRect2/TextureRect2/AnimatedSprite.animation = “historian”

:bust_in_silhouette: Reply From: jgodfrey

It looks like you’re just assigning a specific, named animation when the button is pressed. Depending on your needs, you could store your various animation names in an array and present them from there.

You could store your current array index in a variable and each time you press the button, you could increment your array index variable and load the animation stored at that index. Once the last animation is loaded, another button press could load the first one again.

You could easily expand on that by providing 2 buttons, one to move forward through the animation array and one to move backwards.