Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(2 edits)

I'm very glad that you enjoyed it!! Thank you for playing!! It can be a bit longer, if you need more help say me and we can contact with other method. What I did was: I created an empty game object named "buttons" on the UI and added all the buttons that I want as child elements(TextMeshPro with Button component). I created one script named "UIButtons" and added to the empty game object (the parent). What this script makes it he following: It checks with a foreach all the child elements of the transform. If the child has a button component, adds it to a list. I have a variable named currentIndex, being the index of the selected button. I use the New Input System but basically what I did is: when the player move up, it substract 1 to currentIndex, if the player moves down, it adds 1 to currentIndex. With this you have the system running selecting the buttons. To add color or effect to the one that is selected, I created a function named "SelectButton(bool isSelected)". This function takes the button[currentIndex] and add the effect. Let's name it changing the color. so if isSelected is FALSE it change the color of the text to white, if it's TRUE it change it to yellow. So the algorythm is something like this:

Variables: buttonList, currentButton, currentIndex

Awake: Search the childs that has a GetComponent<Button>() != null and add the buttons to the list.

Start: SelectButton() <- Select the first button (index 0) of the list.

MoveBtwButtons() <- Called by your input system. SelectButton(false) first to deselect the currentButton. Add or substract 1 to the current index depending the Y input. SelectButton(true) to select the new currentButton.

ExecuteOnClick() <- With this I execute the currentButton onClick with the action button of your input system :)

That's how I managed it. SelectButton() at the start will select your first element. If you need something more please ask me! Hope I explained it well!

Thanks!  That helped, I really appreciate it.  :D

You're welcome! If you try it sometime and upload it let me know!!