Skip to content
Snippets Groups Projects
SoundManager.cs 1.04 KiB
Newer Older
  • Learn to ignore specific revisions
  • MaZiFAU's avatar
    MaZiFAU committed
    using UnityEngine.UI;
    
        public static SoundManager Instance { get; private set; }
    
        [SerializeField] Slider volumeSlider;
        public const float defaultVolume = 0.5f;
    
            if (!PlayerPrefs.HasKey("soundVolume"))
    
                PlayerPrefs.SetFloat("soundVolume", defaultVolume);
    
            if (Instance == null)
    
                if (gameObject.IsRoot())
                    DontDestroyOnLoad(gameObject);
            }
            else
    
        private void OnDestroy()
        {
    
            Instance = null;
    
        public void ChangeVolume()
        {
            AudioListener.volume = volumeSlider.value;
            Save();
        }
    
        private void Load()
        {
            volumeSlider.value = PlayerPrefs.GetFloat("soundVolume");
        }
    
        private void Save()
        {
            PlayerPrefs.SetFloat("soundVolume", volumeSlider.value);
        }
    }