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?