Adding an extra variable to GUI buttons?

The question is quite simple, Is it possible to add extra variables to a button, for example, if I have multiple buttons, could I add some sort of ID for each button?
I’m asking this since I am trying to make some sort of an inventory system and what I have in mind would work perfectly if I’d be able to access buttons individually by IDs.

EDIT: here’s the code I already have:

var Icon : Texture2D = null;
var invOffset : float = 50;
var windowRect : Rect = Rect (10, 10, (200), (200));
var invButton : boolean = false;

function OnGUI () 
{
    invButton = GUI.Toggle(Rect((Screen.width/2),(Screen.height-20),100,20),invButton, "Inventory");
    if(invButton)
    {
        GUI.Window (0, windowRect, makeSlots, "Inventory");
	}
}

function makeSlots () 
{
    for(var x : int = 0; x < 5; x++)
    {
        for(var y : int = 0; y < 5; y++)
            if (GUI.Button (Rect (x*40,y*40,30,30), Icon)) 
            {
                print ("clicked the button on row and column: " +(y+1) +(x+1));
            }
    }
    GUI.DragWindow (Rect (0,0,10000,10000));
}

So basically all that I would need to have is a list of all items, and a way to see in which slot they are(if in any). Or at least thats all I think I need…

Create a custom button class, that inherits from the basic unity button class

Then in this class add the extra functionality you would like, for example the item that the button holds. You should then use this new class instead of the basic unity button class.

The new class could look like this (I'm unfamiliar with JavaScript, so I'll write it in C#):

public class CustomButton : GUI.Button
{
    Item item = new Item() //This adds an Item class to the CustomButton class.
    int buttonID;          //This is the ID you wanted.

    void displayIcon()
    {
        //Add some code to display the icon.
    }

    //add any other logic you might need.
}

Then you'd best create an array of CustomButtons to hold the required number of buttons.

You could create an array of buttons I suppose:

int buttonAmount = 1;
Rect buttonPos = new Rect(0,0,50,50);
for(int i=0; i < buttonAmount; i++)
    {
buttonPos.height+=55;
if(GUI.Button(buttonPos,"button " + i))
{
    switch(i)
    {
    case 1:
        //set a variable or call a function?
        break;
    default:
        //huh? maybe a button wasn't pressed
    }
}

Leave a comment! I’d be glad to come back and try to help if this wasn’t the answer you were looking for.