Hello Guys,
I’m trying to instantiate one button for every AudioFile in my array. My problem is that every button plays the same file and I don’t really know why.
Here a small Codesnippet of my For-Loop.
for (int i=0; i<audioFiles.Length; i++) {
GameObject button = (GameObject)Instantiate (buttonPrefab);
button.GetComponent<Button>().onClick.AddListener(
() => {PlayAudio(i);}
);
}
With 2 AudioFiles in use every Button get the Parameter “2”. But why? I’m looking for a small workaround now but what I don’t get is that i should never have the value 2?
Hope my explanation was clear enough.