A few GUI related questions.

Hello, I am trying to make a grid of 4 by 4 buttons and have successfully made them appear within my game, however, I have no idea how to call other functions when they are pressed. I am using an Array to create the text images obviously, but I am having trouble figuring out how to call each one.

On a different not, if I wanted this grid of buttons to be within a window, what exactly would I need to do? Because currently I cannot stop the window from covering the grid.

Also, I would love it if the buttons in the grid would cause a function to run while they are being hovered over by the players mouse.

If anyone has any suggestions I'd really appreciate it!

Basically using this setup:

var Skin2 : GUIStyle;
var GridInt : int = 0;
var GridImage : Texture[];

function OnGUI(){
GridInt = GUI.SelectionGrid (Rect (200, 100, 400, 400), GridInt, GridImage, 4, Skin2);

I cut out the rest of the script, so it wasn't overly cluttered

Thank ~Craze

As you have probably figured out by now, your variable "GridInt" always shows the current selection of the grid.

What do you mean by the window "covering" the grid? Is the window on top of the grid instead of underneath?

What do you want to achieve if the user hovers over a button of yours? If you just want to change the color or texture of the button or its text, you best use the parameters for onHover in your variable for the GUIStyle in the inspector.

Another possiblity is to check in the update function, if the mouse is over a specific button in your grid.

To do this you can check the mousePosition with Input.mousePosition and check for each of the Rects of your buttons if it the position of the mouse is in the Rect. See here for the Scripting Reference: http://unity3d.com/support/documentation/ScriptReference/Rect.Contains.html .

There might be a better way to achieve this, but it is the first solution that came to mind for me.