using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using NaughtyAttributes; public class VerticalButtonNavigation : MonoBehaviour { [SerializeField] private bool isCharacterSelectionButton = false; [SerializeField, ShowIf(nameof(isCharacterSelectionButton))] private Selectable playButton; private Selectable selectable; private Navigation selectableNav; private void Awake() { selectable = GetComponent(); selectableNav = selectable.navigation; SetNavigation(); } private void SetNavigation() { selectableNav.mode = Navigation.Mode.Explicit; int index = transform.GetSiblingIndex(); int lastIndex = transform.parent.childCount - 1; if (index != 0) { selectableNav.selectOnUp = transform.parent.GetChild(index - 1).GetComponent(); } if(index != lastIndex) { selectableNav.selectOnDown = transform.parent.GetChild(index + 1).GetComponent(); } selectableNav.selectOnLeft = null; selectableNav.selectOnRight = isCharacterSelectionButton ? playButton : null; selectable.navigation = selectableNav; } }