Setting up GUI buttons with different states -

I’m hoping there’s a relatively easy way to do this through GUI buttons…I have created an arbitrary number of buttons (amount of buttons chosen in the inspector) in a for loop. Right now, they are all labeled "Button " + i.ToString, giving me Button 0 through Button 9 if I set the variable NumberOfButtons to 10.

What I’d like to be able to do us use my game pad to cycle through the buttons…as I use the horizontal axis, the next button is highlighted. If I press “fire 1”, for instance, that highlighted button will activate.

I understand how to make single buttons, and I understand how to make them execute code when pressed with a mouse, but this is beyond me to set up. So far, I have the for loop in the GUI and that is about it…

for (var i=0;i>numberOfButtons;i++)
        {
        GUI.Button(Rect(8+(i*100),64,60,60), "Button " +i.ToString());
        }

This works fine, but where do I go from here in order to have the first button be ‘selected’ as if the mouse is hovering from the start, and then how do I scroll through the selection using my gamepad?

I know there’s a lot to the question, but thanks so much for the help!

Would look something like this:

var selected:integer = 0;

function Update()
{
	if(Input.GetAxis("Horizontal") > 0.1)
	{
		selected -= 1;
	}else if(Input.GetAxis("Horizontal") <= -0.1)
	{
		Selected += 1;
	}
}

function onGUI()
{
	for (var i=0;i>numberOfButtons;i++)
	{
			if(i == selected)
			{
					GUI.Button(Rect(8+(i*100),64,60,60), "--> Button " +i.ToString());
			}else{
					GUI.Button(Rect(8+(i*100),64,60,60), "    Button " +i.ToString());
			}                
	}
}

That said, the 0.1 values will probably have to be tweaked, but you should get the general idea.

EDIT: Oh, and you’ll have to make the selected loop or stop at 0 and 9. Forgot to add that in, but you should be able to do that.