/// <summary> /// Plays music according to the enum passed in. /// </summary> /// <param name="musicToPlay"></param> public void playMusic(InGameMusic musicToPlay) { if (theme.State == SoundState.Stopped) { switch (musicToPlay) { case InGameMusic.Siren: if (bgm.State != SoundState.Playing) { bgm = siren.CreateInstance(); bgm.IsLooped = true; bgm.Play(); previousBgm = InGameMusic.Siren; } break; case InGameMusic.PowerSiren: bgm.Stop(); bgm = powerSiren.CreateInstance(); bgm.IsLooped = false; bgm.Play(); break; case InGameMusic.Intermission: if (bgm.State != SoundState.Playing) { bgm.Stop(); bgm = intermission.CreateInstance(); bgm.IsLooped = true; bgm.Play(); } break; } } }
public static void PlaySound(InGameMusic sound) { if (musicAudioObject == null) { musicAudioObject = new GameObject("Music"); _musicAudioSoure = musicAudioObject.AddComponent <AudioSource>(); } _musicAudioSoure.PlayOneShot(GetAudioClip(sound)); }
private static AudioClip GetAudioClip(InGameMusic sound) { foreach (InGameAssetManager.InGame_Music soundClip in InGameAssetManager.i.inGame_Musics) { if (soundClip.sound == sound) { return(soundClip.audioClip); } } Debug.LogError("AudioClip Not Found"); return(null); }
void Awake() { if (Instance) { Destroy(gameObject); return; } Instance = this; if (SceneManager.GetActiveScene().name != "TheEnd" || SceneManager.GetActiveScene().name != "Main Menu") { DontDestroyOnLoad(this.gameObject); } }
/// <summary> /// Loads all the sounds. /// </summary> public GameSound(Microsoft.Xna.Framework.Game Game) { //Content.RootDirectory = "Content"; beginning = Game.Content.Load <SoundEffect>(@"sounds/pacman_beginning"); siren = Game.Content.Load <SoundEffect>(@"sounds/pacman_siren"); powerSiren = Game.Content.Load <SoundEffect>(@"sounds/pacman_powersiren"); chomp = Game.Content.Load <SoundEffect>(@"sounds/pacman_chomp"); death = Game.Content.Load <SoundEffect>(@"sounds/pacman_death"); eatFruit = Game.Content.Load <SoundEffect>(@"sounds/pacman_eatfruit"); eatGhost = Game.Content.Load <SoundEffect>(@"sounds/pacman_eatghost"); eatPowerPill = Game.Content.Load <SoundEffect>(@"sounds/pacman_eatpowerpill"); intermission = Game.Content.Load <SoundEffect>(@"sounds/pacman_intermission"); theme = beginning.CreateInstance(); bgm = siren.CreateInstance(); previousBgm = InGameMusic.PowerSiren; }