-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOptionsMenuController.cs
45 lines (39 loc) · 1.27 KB
/
OptionsMenuController.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
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
using TMPro;
public class OptionsMenuController : MonoBehaviour
{
public AudioMixer audioMixer;
public TMP_InputField nameText;
public Slider musicSlider, fxSlider, accelSlider;
void Start()
{
nameText.text = PlayerPrefs.GetString("PlayerName", "Anon");
musicSlider.value = PlayerPrefs.GetFloat("MusicVolume", 0.75f);
fxSlider.value = PlayerPrefs.GetFloat("FXVolume", 0.75f);
accelSlider.value = PlayerPrefs.GetFloat("Acceleration", 2f);
}
public void SetName(string name)
{
if (String.IsNullOrEmpty(name)) nameText.text = "Anon";
else PlayerPrefs.SetString("PlayerName", name);
}
public void SetMusicVolume(float sliderValue)
{
audioMixer.SetFloat("MusicVol", Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat("MusicVolume", sliderValue);
}
public void SetFXVolume(float sliderValue)
{
audioMixer.SetFloat("FXVol", Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat("FXVolume", sliderValue);
}
public void SetAcceleration(float value)
{
PlayerPrefs.SetFloat("Acceleration", value);
}
}