using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class settingsScript : MonoBehaviour { public Text keyvert; public Text keytrans; public Slider volume; public Slider sensi; public Dropdown resol; public AudioSource music; public GameObject panel; private bool changetrans = false; private bool changevert = false; public void ResetSettings() { PlayerPrefs.SetFloat("volume", 0.5f); PlayerPrefs.SetInt("sensi", 100); PlayerPrefs.SetInt("resol", 2); PlayerPrefs.SetInt("keyvert", (int)KeyCode.LeftControl); PlayerPrefs.SetInt("keytrans", (int)KeyCode.LeftShift); Start(); } void Awake() { } void Start() { if (PlayerPrefs.HasKey("volume") == false) ResetSettings(); volume.value = PlayerPrefs.GetFloat("volume"); music.volume = volume.value; sensi.value = PlayerPrefs.GetInt("sensi"); resol.value = PlayerPrefs.GetInt("resol"); var tmp = resol.options[resol.value].text.Split("x"[0]); Screen.SetResolution(int.Parse(tmp[0]), int.Parse(tmp[1]), false); keyvert.text = ((KeyCode)(PlayerPrefs.GetInt("keyvert"))).ToString(); keytrans.text = ((KeyCode)(PlayerPrefs.GetInt("keytrans"))).ToString(); panel.SetActive(false); } public void ShowSettings() { panel.SetActive(!panel.active); } public void ChangeResol() { PlayerPrefs.SetInt("resol", resol.value); var tmp = resol.options[resol.value].text.Split("x"[0]); Screen.SetResolution(int.Parse(tmp[0]), int.Parse(tmp[1]), false); } public void ChangeVolume() { PlayerPrefs.SetFloat("volume", volume.value); music.volume = volume.value; } public void ChangeSensi() { PlayerPrefs.SetInt("sensi", (int)sensi.value); } public void ChangeTranslation() { changetrans = true; changevert = false; } public void ChangeVertical() { changevert = true; changetrans = false; } void Update() { if (changetrans) { foreach (KeyCode key in System.Enum.GetValues(typeof(KeyCode))) { if (Input.GetKey(key)) { PlayerPrefs.SetInt("keytrans", (int)key); keytrans.text = ((KeyCode)(PlayerPrefs.GetInt("keytrans"))).ToString(); changetrans = false; } } } if (changevert) { foreach (KeyCode key in System.Enum.GetValues(typeof(KeyCode))) { if (Input.GetKey(key)) { PlayerPrefs.SetInt("keyvert", (int)key); keyvert.text = ((KeyCode)(PlayerPrefs.GetInt("keyvert"))).ToString(); changevert = false; } } } } }