public void InitModelButtons(Config_Map mapConfig) { _terraintoolkit ??= FindObjectOfType <TerrainToolkit>(); // for each model, add 1 button to parent for (int i = 0; i < mapConfig.Models.Count; i++) { var buttonID = i; var button = Instantiate(_addModelButtonPrefab, _modelBar.transform); button.GetComponent <UI_ModelView>().Init(mapConfig.Models[i].Thumbnail, mapConfig.Models[i].ThumbnailName); button.onClick.AddListener(() => _terraintoolkit.OnClickAddSModel(buttonID)); } }