Unity 4.6, scripting the buttons… Iterate through a directory and create a button for each file… The value of f.Name in the AddListener bit should be set independently for each button. Instead every button has the value of the last f.Name to be processed (the last file alphabetically in the directory). Any ideas?
foreach (FileInfo f in fileInfo) {
Button btnCurrLvl = (Button) Instantiate(btnLvl);
btnCurrLvl.GetComponentInChildren<Text>().text = f.Name.Remove(f.Name.Length-5);
Debug.Log(f.Name); // f.Name is different every time
btnCurrLvl.name = f.Name; // renaming the btns works
btnCurrLvl.GetComponent<Button>().onClick.AddListener(() => LoadLocalLvl(f.Name)); // all the listeners on all created buttons are set to the last value of f.Name!?
}