I have multiple UI-buttons which I want to switch through and select with the standart keyboard keys and gamepad for “Up” and “Down”. I use this code:
private float moveInputY;
moveInputY = Input.GetAxisRaw("Vertical");
if (moveInputY < -0.01f)
{
buttonIndex++;
if (buttonIndex > 3)
buttonIndex = 3;
}
else if (moveInputY > 0.01f)
{
buttonIndex--;
if (buttonIndex < 0)
buttonIndex = 0;
}
My problem is the buttons are switching to fast, it is immediaty on the first button by pressing “UP” and on the last button by pressing “DOWN” (on keyboard, with gamepad I didn’t tested it). I’m sure there is a better way.