-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVolumenManagerScript.cs
51 lines (43 loc) · 1.39 KB
/
VolumenManagerScript.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class VolumenManagerScript : MonoBehaviour
{
[SerializeField] Slider GameVolumenSlider, MusicVolumenSlider;
public static float GameVolumen = 1f, MusicVolumen = 1f;
public GameObject GameMusic, LobbyMusic;
// Start is called before the first frame update
void Start()
{
if (!PlayerPrefs.HasKey("MusicVolumen"))
{
PlayerPrefs.SetFloat("MusicVolumen", 1f);
}
if (!PlayerPrefs.HasKey("GameVolumen"))
{
PlayerPrefs.SetFloat("GameVolumen", 1f);
}
Load(); changeVolumen();
}
public void changeVolumen()
{
MusicVolumen = MusicVolumenSlider.value;
GameVolumen = GameVolumenSlider.value;
if (GameMusic) GameMusic.GetComponent<AudioSource>().volume = MusicVolumen;
if (LobbyMusic) LobbyMusic.GetComponent<AudioSource>().volume = MusicVolumen;
Save();
}
private void Load()
{
MusicVolumen = PlayerPrefs.GetFloat("MusicVolumen");
GameVolumen = PlayerPrefs.GetFloat("GameVolumen");
MusicVolumenSlider.value = MusicVolumen;
GameVolumenSlider.value = GameVolumen;
}
private void Save()
{
PlayerPrefs.SetFloat("MusicVolumen", MusicVolumen);
PlayerPrefs.SetFloat("GameVolumen", GameVolumen);
}
}