Navigation through buttons with custom controller logic
I want make player able to move through buttons collection with gamepad controller. I have custom logic for service gamepad controller. All I want to do is when player for example move down (with gamepad stick for example) then button should be selected. When player will do it again then next button should be selected and the others deselected.
I set my UI elements in editor and assign buttons to script's collection.
There is what I have tried to do:
public void Move()
{
int index = selectedIndex;
index++;
index = index % buttonList.Length;
selectedIndex = index;
buttonList[index].Select();
}
but it's not working (button is not highlighted). I have checked and function is fired up correctly by gamepad controller.
When I tried to set colours on my own then buttons colour change permanently after start game (buttons are grey colour).
There is code:
public void SetupButtons()
{
ColorBlock cb = new ColorBlock();
cb.highlightedColor = new Color(107, 106, 109);
cb.normalColor = new Color(255, 255, 255);
for (int i = 0; i < buttonList.Length; i++)
{
buttonList[i].colors = cb;
}
}
There is something like navigation. I tried to set up it but I don't know how it is managed. I set up it like this:
public void SetupButtons()
{
Navigation customNav = new Navigation();
customNav.mode = Navigation.Mode.Explicit;
for (int i = 0; i < buttonList.Length; i++)
{
int up = System.Math.Abs((i + 1) % buttonList.Length);
int down = System.Math.Abs((i - 1) % buttonList.Length);
customNav.selectOnDown = buttonList[down];
customNav.selectOnUp = buttonList[up];
buttonList[i].navigation = customNav;
}
}
but how I can get control about this navigation system (How change state/transition)?
I tried to explain what I want in easy way but If it is not enough clearly for you, let me know.
Your answer
Follow this Question
Related Questions
Coding click multiplier in C#. Help! 0 Answers
Trouble switching between UI buttons 0 Answers
C sharp script, to open a Unity standalone .exe file on a network drive 0 Answers
can't instantiate gameobject 0 Answers