/// <summary> /// Plays a background music on loop. If a track is already playing, /// stops current track and plays new one. /// </summary> /// <param name="name">the enum name of the track to play</param> public void PlayMusic(MusicSoundEffect name) { if (musicSoundEffectsDict.ContainsKey(name)) { if (musicAudioSource.isPlaying) { musicAudioSource.Stop(); musicAudioSource.clip = musicSoundEffectsDict[name]; musicAudioSource.Play(); musicAudioSource.loop = true; } else { musicAudioSource.clip = musicSoundEffectsDict[name]; musicAudioSource.Play(); musicAudioSource.loop = true; } //set current music enum currentMusic = name; } else { Debug.Log("Music name " + name.ToString() + " is not in the music sound effects dictionary!"); } }
/// <summary> /// Stops the current music /// </summary> public void StopMusic() { if (musicAudioSource.isPlaying) { musicAudioSource.Stop(); currentMusic = MusicSoundEffect.None; } else { Debug.Log("No music is playing to stop."); } }
/// <summary> /// Gets a music from the music dictionary /// </summary> /// <param name="name">the name of the music</param> /// <returns></returns> public AudioClip GetMusic(MusicSoundEffect name) { if (musicSoundEffectsDict.ContainsKey(name)) { return(musicSoundEffectsDict[name]); } else { Debug.Log("Key " + name + " is not in the music dictionary!"); return(null); } }