How to make my game settings save?

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<string> options = new List<string>();

        int currentResolutionIndex = 0;

        for (int i = 0; i < resolutions.Length; i++)
        {
            string option = resolutions_.width + "x" + resolutions*.height;*_

options.Add(option);

if (resolutions*.width == Screen.currentResolution.width &&*
resolutions*.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;
}

You don’t have to use player prefs, but yes that is Unity’s built in solution and it is quite straight forward to use.


Anyhow, I don’t see any attempt to actually use PlayerPrefs inside your code, but if you want to save a string, for example, you would do the following:


string myString = “Howdy”;

//Set the string
PlayerPrefs.SetString( “MY_STRING_KEY”, myString);

//Get the string
string myStringAfterItWasSaved = PlayerPrefs.GetString( “MY_STRING_KEY” );

//myStringAfterItWasSaved == “Howdy”

People who actually need some useful advice, this is a perfect video: Settings Menu with PlayerPref Save System for Unity - YouTube