/// <summary> /// Plaies the sound fx. /// </summary> /// <param name="opt">Opt.</param> public void PlaySoundFx(EnumSounds opt) { //In this enum option we can control audio volume that will apply to all places of game that uses it. //and we can change what will plays. All changes will reflect all calls during game code. switch(opt) { case EnumSounds.Eat: GetComponent<AudioSource>().PlayOneShot(sfxEat,0.75f); break; case EnumSounds.Coin: GetComponent<AudioSource>().PlayOneShot(sfxCoin,0.8f); break; case EnumSounds.Click: GetComponent<AudioSource>().PlayOneShot(sfxClick,1f); break; case EnumSounds.MusicMain: PlayMusic (bgMenu); break; case EnumSounds.MusicLevel: PlayMusic (bgLevel); break; case EnumSounds.MusicWin: PlayMusicEnd(bgWin); break; case EnumSounds.MusicLose: PlayMusic (bgLose); break; } }
public void Play(EnumSounds name) { Sound sound = Array.Find(sounds, sound => sound.name == name); if (!sound.audioSource.isPlaying) { sound.audioSource.Play(); } }