I’m trying to create a script where you can use the XBox Controller D’Pad (Up and Down I would suppose>7th Axis) to cycle through my OnGUI Buttons that I have, basically (Single Player, Multi-Player, Options, etc.)
I have my input manager set up in unity where as it’s “DPadVertical” if this helps you to use in the example code.
You need to keep an array of your buttons and as you cycle through move the index over.
Button buttons = new Buttons
Button currentButton;
int currentIndex;
void Start() {
this.curretIndex = 0;
this.currentButton = this.buttons[this.currentIndex]
}
void MoveUp() {
if((this.currentIndex - 1) > -1) {
this.currentIndex–;
} else {
this.currentIndex = size - 1;
}
this.currentButton = this.buttons[this.currentIndex];
}
Do the reverse for going down. This is assuming the first button in your array is the first option in your menu list. I wrote this up on my phone sorry for the shit format.
Thanks for your reply! I’m a bit confused at the starting point of your structure.
Button buttons = new Buttons
Button currentButton;
int currentIndex;
Does that go in the array?
Its abstract, essentially “Buttons” is whatever your Menu Grid is made up of. If you are using Unity’s OnGUI then you need to make an array of GUI.Button. If you are using NGUI, then UIButton is what you are looking for. Size is the amount of buttons you have.
Alright! Thanks, I’ll try that. I really appreciate your time!