public void InitialiseButtons() { if (_selectFileButtons != null) { foreach (var button in _selectFileButtons) { Destroy(button.gameObject); } _selectedFileButton = null; _selectFileButtons.Clear(); } var saveDirectories = GameFile.GetSaveDirectories(); _selectFileButtons = new List <MyButton>(); // Create a new load save button for each save game on the client for (int i = 0; i < saveDirectories.Length; ++i) { MyButton selectFileButton = Instantiate(SelectFileButtonPrefab, _selectFileScrollView); int e = i; selectFileButton.OnClick.AddListener(delegate { SelectFileButton(selectFileButton, saveDirectories[e]); }); selectFileButton.GetComponentInChildren <TextMeshProUGUI>().text = saveDirectories[i].Name; _selectFileButtons.Add(selectFileButton); } }