Last active
February 6, 2025 12:10
-
-
Save kurtdekker/01da815d2dfd336a925ae38019c3a163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// by @kurtdekker - handy example of simple persistent settings. | |
// | |
// To use, just use the variables like any other: | |
// | |
// SETTINGS.VolumeLevel = 1.0f; | |
// | |
// if (SETTINGS.EnableTurboMode) | |
// { | |
// // Do turbo-mode stuff | |
// } | |
// | |
// EDIT: see defaults that you can set below | |
public static class SETTINGS | |
{ | |
// change this if you want it to start out differently | |
private const float DefaultVolumeLevel = 1.0f; | |
private static string s_VolumeLevel = "VolumeLevel"; | |
public static float VolumeLevel | |
{ | |
get | |
{ | |
return PlayerPrefs.GetFloat(s_VolumeLevel, DefaultVolumeLevel); | |
} | |
set | |
{ | |
PlayerPrefs.SetFloat(s_VolumeLevel, value); | |
} | |
} | |
private const bool DefaultTurboMode = true; | |
private static string s_EnableTurboMode = "EnableTurboMode"; | |
public static bool EnableTurboMode | |
{ | |
get | |
{ | |
return PlayerPrefs.GetInt(s_EnableTurboMode, DefaultTurboMode ? 1 : 0) != 0; | |
} | |
set | |
{ | |
PlayerPrefs.SetInt(s_EnableTurboMode, value ? 1 : 0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment