Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / UI / Pause Menu / Options Menu / OptionsInGameMenu.cs
@Rackday Rackday on 18 Aug 792 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Audio;
  5. using UnityEngine.UI;
  6. public class OptionsInGameMenu : MonoBehaviour
  7. {
  8. public AudioMixer audioMixer;
  9. public Slider volumeSlider;
  10. private void Start()
  11. {
  12. if (!PlayerPrefs.HasKey("musicVolume"))
  13. {
  14. PlayerPrefs.SetFloat("musicVolume", 1);
  15. Load();
  16. }
  17. else
  18. {
  19. Load();
  20. }
  21. }
  22. public void ChangeVolume()
  23. {
  24. AudioListener.volume = volumeSlider.value;
  25. Save();
  26. }
  27. private void Load()
  28. {
  29. volumeSlider.value = PlayerPrefs.GetFloat("musicVolume");
  30. }
  31. private void Save()
  32. {
  33. PlayerPrefs.SetFloat("musicVolume", volumeSlider.value);
  34. }
  35. }