How to identify which prefab clicked out of array of cloned prefabs

Hello,

I have an array of randomly generated ball prefabs.


I can check that I am clicking on any ball prefab because the ball prefab, called N-back in the picture above (with many clones as you can see) , has a script attached with this method:

private void OnMouseDown()
    {
        print("clicked");
    }

Yet I want to be able to identify which specific ball I am clicking because eventually I want the user to click them in order trying to remember the order in which the balls were instantiated on the screen, because I instantiate them one by one in random order.
I don’t know how to identify which ball/gameObject/clone of the list created is being clicked by my mouse.
I tried to print the name of each, they all have the same name. The positions are obviously different but I don’t know how this information would be useful to distinguish the balls on click.
Any suggestion would be much appreciated :slight_smile:

It’s up to you. Do you want the names to be different? Then assign the names you want to each Prefab instance right after you instantiate it. Do you want to work with a number instead of a name? Then create a public int myNumber on your script (perhaps the same script that has OnMouseDown), and assign a number to that public variable for each Prefab, right after you instantiate the Prefab. Basically, you create the data you need yourself, and then read it later.