So basically, I have a song selection menu in my game, I am using two buttons as arrows, one on the left and one on the right, obviously, the left button would go - in the array and the right arrow would go + in the array, but nooby me, can’t achieve this, I can tell its a super simple process, but what I have just goes from 0 to 14 instead of going from 0,1,2,3… etc. (array of 15 items). The “Song Ref” is the selection of the song which gives the output.
public Button leftBtn;
public Button rightBtn;
[Space]
[Header("Array Ref")]
public GameObject songRef;
[Space]
[Header("Song Game Objects")]
public GameObject[] array;
public int selection;
private bool leftButtonIsPressed;
private bool rightButtonIsPressed;
void Start()
{
selection = 0;
}
void RightButtonPressed()
{
if (selection < array.Length - 1) //because size starts at 1, arrays at 0
{
selection++;
}
}
void LeftButtonPressed()
{
if (selection > 0)
{
selection--;
}
}
void Update ()
{
rightBtn.onClick.AddListener(RightButtonPressed);
leftBtn.onClick.AddListener(LeftButtonPressed);
songRef = array[selection];
//change song using refrence
}