void Awake() { backgroundMusicState = backMusicState.STOPED; backgroundMusicSource = gameObject.AddComponent <AudioSource>(); backgroundMusicSource.clip = Resources.Load <AudioClip>(FilePaths.soundFolder + "theme"); soundSource = gameObject.AddComponent <AudioSource>(); }
public void StopBackgroundMusic() { if (backgroundMusicSource.isPlaying && backgroundMusicSource != null) { backgroundMusicSource.Stop(); backgroundMusicState = backMusicState.STOPED; } }
public void PauseBackgroundMusic() { if (backgroundMusicSource.isPlaying && backgroundMusicSource != null) { backgroundMusicSource.Pause(); backgroundMusicState = backMusicState.PAUSED; } }
// background music functions public void PlayBackgroundMusic() { backgroundMusicSource.loop = true; if (!backgroundMusicSource.isPlaying) { if (backgroundMusicState == backMusicState.STOPED) { backgroundMusicSource.PlayOneShot(backgroundMusicSource.clip, SoundInfo.backgroundSoundInfo.volume * (SoundOptionsGlobal.masterVolume / 100)); backgroundMusicState = backMusicState.PLAYING; } else if (backgroundMusicState == backMusicState.PAUSED) { backgroundMusicSource.UnPause(); backgroundMusicState = backMusicState.PLAYING; } } }