- Home /
The first object in selection grid can't be activated. Why?
Essentially what I said in the title. This is my code:
#pragma strict
//@ExecuteInEditMode
var customButton : GUIStyle;
var confirmMenu : GUIStyle;
var SubMenuBox1 : GUIStyle;
var SubMenuBox2 : GUIStyle;
var selGridInt : int = -1;
var selGridInt2 : int = 0;
var selStrings2 : String[] = ["Yes", "No"];
var selStrings1 : String[] = ["Sandbox", "Multiplayer", "Options", "Exit"];
//var MainMenu:GUISkin;
//var Rect2 = RectOffset(0,0,10,10);
//var sliderValue : float = 1.0;
//private var rctOff : RectOffset;
function Start(){
}
//#if UNITY_EDITOR #endif
function OnGUI () {
selGridInt = GUI.SelectionGrid (Rect (Screen.width*0.015625, Screen.height*0.014286, 75, 95), selGridInt, selStrings1, 1, customButton);
if (selGridInt == 0){
Application.LoadLevel("gameDemo");
}
if (selGridInt == 1){
Application.LoadLevel("");
}
if (selGridInt == 2){
//GUI.Box(Rect(Screen.width/2, Screen.height/2, 100, 200, "Are you sure?", confirmMenu));
selGridInt2 = GUI.SelectionGrid (Rect (Screen.width/2, Screen.height/2, 75, 25), selGridInt2, selStrings2, 2, customButton);
if(selGridInt2 == 1){
Application.LoadLevel(Application.loadedLevel);
}
//if(selGridInt2 != 1||0){
//System.Diagnostics.Process.GetCurrentProcess().Kill();
//}
}
}
Is it the same with both grids? Does the mouse over effect still appear?
Not sure if this works (just an idea): In GUI.SelectionGrid the selGridInt parameter is "The index of the selected grid button". Since it represents an index it might be internally clamped. So, your initial value of -1 might not work (an index must be >= 0). If you set the initial value of selGridInt to 0 does it make any difference?
No. Changing the value doesn't seem to affect the result.
:D The IT Crowd (but you don't get an upvote since it's pointless for the question and we're not Youtube or Facebook.)
Answer by pako · Oct 22, 2013 at 09:42 AM
I made a test scene and copied your code. I also created dummy scenes "gameDemo" and "Multiplayer" and added them to the build settings. I changed line 29 to load the Multiplayer scene.
Well, it all works on my machine. The scenes open as expected, the options open as expected, and the Yes/No buttons of the options work as expected. So, it's not a problem with the code. Maybe there's something wrong with the input. Probably your mouse isn't detected for some reason.