SelectionGrid layout and style issues

I'm trying to make a Level Select screen for my game using GUI.SelectionGrid but I'm having a couple problems:

  1. I applied a GUIStyle to my SelectionGrid which includes a "hover" style. This works fine EXCEPT on the very first element of the grid, which doesn't change color when hovered over (this is the same with "active" as well as "hover")

  2. It seems that when I click, even if I don't click on one of the grid buttons, it registers the nearest one as active, so I could click in the very far corner but it will think I'm clicking on one of the buttons

Code:

    using UnityEngine;
using System.Collections;

public class LevelSelect : MonoBehaviour {
    private int levelCount;
    private int selected = -1;
    private string[] grid;
    public GUIStyle style;

    void Start()
    {
        levelCount = Application.levelCount-2;
        grid = new string[levelCount];
        for(int i = 0; i < levelCount; i++)
        {
            grid *= "Level " + i;* 
 *}* 
 *}*
 *void OnGUI() {*
 *selected = GUI.SelectionGrid(new Rect(0,0, Screen.width, Screen.height), 0, grid, 5, style);*
 *if(Input.GetMouseButtonUp(0))*
 *{*
 *Application.LoadLevel(selected+2);*
 *}* 
 *}*
*}*
*```*

Might be outdated seeing how the question is months old, but hope this helps.

  1. I’m guessing you initialized the value of selected to 0 (the first element), thereby setting your first element as the selected element. The way SelectionGrid seems to be implemented, the currently selected element will not react to the “hover” defined in your GUIStyle (someone correct me if I’m wrong). Try selecting another element, then check to see if your first element now properly shows “hover” effects (if it still doesn’t, I’m out of ideas).

  2. The Input.GetMouseButton function is a global input handler, not specific to your active GUI component, hence the behaviour you are getting… Because of the way GUI.SelectionGrid is called, we cannot directly define a handler for it.

Might not be the best way to go about it, but this is how I did it previously:

void OnGUI() {
    int prevSelection = selected;
    selected = GUI.SelectionGrid(new Rect(0, 0, Screen.width, Screen.height), 0, grid, 5, style);

    if (prevSelection != selected) {
        Application.LoadLevel(selected+2);
    }
}