What's the best way of differentiating instances of button prefabs?

I’m making a dynamically generated page which displays an array of items and a “Select” button for each of these items.

But when player press one of the “Select” button, the script needs to know to which item this button is referring.

What would be the most efficient way to do that?
Should I add a tag with an integer to each button? (the integer would refer to the item’s ID). Isn’t there a better way than tags?

Thanks in advance

Well, I suggest you to make a custom control that contains a button…

For example, I suppose that you have a for loop, where you show all the buttons… Well, I would do something like that:

//(It's in C#, you didn't specify which language did you use, so I will make the script in the one I prefer)

using UnityEngine;
using System.Collections;

public class MyClass: MonoBehaviour {

	//This is the item you have clicked...
	CustomItem clickedItem;

	void OnGUI() {
		for (int i = 0; i < totalItems; i++) {
			CustomItem item = new CustomItem();
			item.name = "I'm a custom item (" + i + ")";
			if(TheButton(new Rect(position...), "bla bla bla", item)) {
				//Something to do...

	bool TheButton(Rect rect, string content, CustomItem item) {

		Vector2 mousePos = Event.current.mousePosition;
		bool returnBool = GUI.Button(rect, content);

		if(rect.Contains(mousePos) && returnBool) { //This mean that a item was clicked so now we have to send it to the general variable...
			clickedItem = item;

		return returnBool;


	//Now with the custom item we can do the thing you want for example show in the console the one we selected...

	void Update() {

		if(clickedItem != null) { 
            //If you want now to be spammed you have to null clickedItem at the end of 'void OnGUI()' ;)



public CustomItem {
	public string name; 
    //There you can set all the properties you want

I hope this helps… Bye! ^^