public void DisplayAndPlayMusicInstrument() { DestroyEverything(); string folderName = DropdownMusic.options[DropdownMusic.value].text; string musicFolderPath = _dictionnaryMusic[folderName]; var score = (GameObject)Resources.Load(folderName + "/" + folderName + "Score", typeof(GameObject)); if (score != null) { Debug.Log(score); score = Instantiate(score, transform); } int i = 1; foreach (var track in Directory.GetFiles(musicFolderPath).Where(n => (Path.GetExtension(n) == ".mp3") || (Path.GetExtension(n) == ".wav"))) { Slider slider = Instantiate(VolumeSlider); slider.transform.SetParent(Canvas.transform, false); slider.transform.Translate(new Vector3(-20, -i, 0)); slider.onValueChanged.AddListener(delegate { ChangeVolume(slider, Path.GetFileName(track)); }); Button goButton = Instantiate(MuteButton); goButton.transform.SetParent(Canvas.transform, false); goButton.GetComponentInChildren <Text>().text = Path.GetFileName(track); goButton.transform.Translate(new Vector3(i, 0, 0)); goButton.transform.localScale = new Vector3(0.85f, 1, 1); goButton.onClick.AddListener(() => { if (_sources.ContainsKey(goButton.GetComponentInChildren <Text>().text)) { if (Math.Abs(_sources[goButton.GetComponentInChildren <Text>().text].Volume) > 0.2) { _sources[goButton.GetComponentInChildren <Text>().text].Volume = 0; slider.value = 0; } else { _sources[goButton.GetComponentInChildren <Text>().text].Volume = 1; slider.value = 1; } } }); FMOD.Sound sound = _audioMixer.Load(track); CustomAudioSource source = Instantiate(SourcePrefab).GetComponent <CustomAudioSource>(); OrchestraPrefab.AddSource(source); source.SetSound(sound); _sources.Add(Path.GetFileName(track), source); _sliders[slider] = source; Source = source; i += 30; } //OrchestraPrefab.MutedSourceJustForDefaultSpeed; foreach (var source in _sources) { source.Value.Play(); } }