Second button of SelectionGrid always pressed

Hello,

I’m trying to setup a 3 row by 2 column selection grid with the upper left button initially selected.

My code:

var selectionState :int =0;
var selectionLabels : String[]=["1","2","3","4","5","6"];

function OnGUI () 
{
selectionState = GUI.SelectionGrid(Rect(10,100,100,150),selectionState,selectionLabels,2);
}

However, when I click the play button, button 2 (upper right) is always selected. In fact, it doesn’t matter what number I put in for var selectionState, 2 always starts selected.

Clicking on a button changes it as expected, so it is only the initial setup that is weird.

How do I make it so button 1 (upper left) is the one initially selected?

Thanks.

Your problem probably is that the variable selectionState is a public var, what makes it appear in the Inspector. If you ever changed its value in the Inspector, this value will plague you for the rest of your life! You can change your script a thousand times, but the Inspector always restore the value you’ve set once.

Just set the initial value you want at the Inspector, and it will be valid for the eternity.