UISoundSettings.cs 1.4 KB
Newer Older
radow's avatar
radow committed
1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UISoundSettings : MonoBehaviour
{
    public static float musicVolume;
    public static float effectsVolume;
    public static float vaVolume;

    public static float musicVolumeDefault = 1;
radow's avatar
radow committed
13
14
    public static float effectsVolumeDefault = .3f;
    public static float vaVolumeDefault = .7f;
radow's avatar
radow committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

    public Slider musicVolumeSlider;
    public Slider effectsVolumeSlider;
    public Slider vaVolumeSlider;

    public void SetMusicVolume(System.Single vol)
    {
        musicVolume = vol;
        PlayerPrefs.SetFloat("musicVolume", musicVolume);
    }
    public void SetEffectsVolume(System.Single vol)
    {
        effectsVolume = vol;
        PlayerPrefs.SetFloat("effectsVolume", effectsVolume);
    }
    public void SetVAVolume(System.Single vol)
    {
        vaVolume = vol;
        PlayerPrefs.SetFloat("vaVolume", vaVolume);
    }

    public static void LoadSoundSettingsLocally()
    {
        musicVolume = PlayerPrefs.GetFloat("musicVolume", musicVolumeDefault);
        effectsVolume = PlayerPrefs.GetFloat("effectsVolume", effectsVolumeDefault);
        vaVolume = PlayerPrefs.GetFloat("vaVolume", vaVolumeDefault);
    }

    private void OnEnable()
    {
        musicVolumeSlider.value = musicVolume;
        effectsVolumeSlider.value = effectsVolume;
        vaVolumeSlider.value = vaVolume;
    }

}