- Home /
Question by
ionside · Mar 23, 2017 at 02:06 PM ·
buttonnavigationmode
UI navigation.mode not changing
I need to change the navigation mode on a group of buttons at runtime.
I currently have a coroutine with a loop inside to change a group.
IEnumerator ButtonInitialize()
{
yield return new WaitForEndOfFrame();
foreach (Transform button in buttonList.transform)
{
//if(button.name.Contains("buildButton"))
if (button.CompareTag("NavButton"))
{
Debug.Log(button.name);
bNavigation = button.GetComponent<Button>().navigation;
bNavigation.mode = Navigation.Mode.None;
}
}
}
Unfortunately the navigation mode isn't being changed.
How could I rectify this?
Comment
A friend has shown me my mistake. I want to set the navigation.mode per button but my code says otherwise. I need to iterate over an array of the buttons with a for loop, and instantiate the Navigation per button.
Best Answer
Answer by Probe-Games · Mar 24, 2017 at 12:20 PM
This isn't cleaned up properly but it will work.
public Button[] buttonList;
void Start(){
ChangeMode ();
}
public void ChangeMode(){
for (int i = 0; i < buttonList.Length; i++) {
Navigation n = new Navigation ();
n.mode = Navigation.Mode.None;
buttonList [i].navigation = n;
}
}