Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

How to make my game settings save?

$
0
0
I've got a working settings menu, with a volume slider, resolution dropdown, etc. The problem is the settings don't get saved, when transitioning to a different scene, or when restarting the game. I know I have to use PlayerPrefs, but I just don't know how to implement it into my code, would appreciate if anyone could help. Here is my settings menu code: public AudioMixer audioMixer; Resolution[] resolutions; public TMPro.TMP_Dropdown resolutionDropdown; void Start() { resolutions = Screen.resolutions; resolutionDropdown.ClearOptions(); List options = new List(); int currentResolutionIndex = 0; for (int i = 0; i < resolutions.Length; i++) { string option = resolutions[i].width + "x" + resolutions[i].height; options.Add(option); if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height) { currentResolutionIndex = i; } } resolutionDropdown.AddOptions(options); resolutionDropdown.value = currentResolutionIndex; resolutionDropdown.RefreshShownValue(); } public void setResolution(int resolutionIndex) { Resolution resolution = resolutions[resolutionIndex]; Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen); } public void setVolume(float volume) { audioMixer.SetFloat("volume", volume); } public void setQuality(int qualityIndex) { QualitySettings.SetQualityLevel(qualityIndex); } public void setFullscreen(bool isFullscreen) { Screen.fullScreen = isFullscreen; }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>