Accessing a certain prefab and it's children

I have a list of items that is used to instantiate a list of button prefabs. Each of this buttons has a Text child that displays the name of the item attached to it/the item that spawned it.

I tried to attach a Script to these buttons that displays the values of the item the button referes to in another Panel. I tried to do it with a loop that searches through the item list and stops when the textdisplay on the button is equal to the item name.
This however always returned the values of the first item in the list.
Via Debugging I figured out that the script doesn’t compares the display text on the button that was clicked but all display texts on all prefab clone buttons.
So I obviously need a way to specify that I only want to compare the text on the button that was clicked and not all of them. I spent the last three hours googling for a solution and tried out different things, but nothing worked so far.

The most recent version looks like this:

private void OnMouseDown()
    {
        SetWriterData(gameObject.GetComponentInChildren<Text>());
       
    }

 public void SetWriterData(Text currentname)
    {
       


        for (int i = writerlist.Count - 1; i >= 0; i--)
        {
            

            if (currentname.text == writerlist*.name)*

{

Name.text = writerlist*.name;*
Intel.text = writerlist*.intelskill.ToString();*
Complex.text = writerlist*.complexskill.ToString();*
Pace.text = writerlist*.paceskill.ToString();*
Dialogue.text = writerlist*.paceskill.ToString();*
Humor.text = writerlist*.humorskill.ToString();*

}
}

}
How can I solve this problem? Is what I’m trying to do possible? Is there a better way to do it?

If I understand you well, you want to only access to the button clone that you have spawned and not directly to the button prefab itself (whose the text is the same for all), that’s right ?

To access only to the clone that spawned, you have to create a reference of it first when you spawn the prefab on the scene.

To do that, when you have declared your prefab GameObject variable like this :

//Here's the variable you have linked to the prefab in the inspector
public Gameobject buttonPrefab;

when you instantiate the prefab do that :

GameObject buttonClone = Instantiate (buttonPrefab) as GameObject;

instead of just

Instantiate (buttonPrefab);

then re-use your reference to access to the component you want, for example :

Text buttonCloneText = buttonClone.GetComponent<Text>();

if (buttonCloneText != null)
{
//Do something here
buttonCloneText.text = "I'm a button clone !";
}