private void Awake() { if (config == null) { DontDestroyOnLoad(gameObject); //makes instance persist across scenes config = this; } else if (config != this) { Destroy(gameObject); //deletes copies of global which do not need to exist, so right version is used to get info from } PlayerPrefKeys.CheckKeys(); }
// Start is called before the first frame update void Start() { lockout = true; PlayerPrefKeys.CheckKeys(); // music volume int volume = (int)(PlayerPrefs.GetFloat(PlayerPrefKeys.musicVolumeKey) * 10); musicSlider.GetComponent <Slider>().value = volume; musicVolumeText.text = (volume * 10).ToString() + '%'; // sound effects volume volume = (int)(PlayerPrefs.GetFloat(PlayerPrefKeys.soundEffectsVolumeKey) * 10); soundEffectsSlider.GetComponent <Slider>().value = volume; soundEffectsVolumeText.text = (volume * 10).ToString() + '%'; bool isOn; // vibration enabled if (System.Boolean.TryParse(PlayerPrefs.GetString(PlayerPrefKeys.vibrationEnabledKey), out isOn)) { vibrationToggle.GetComponent <Toggle>().isOn = isOn; } else { // unable to parse vibrationToggle.GetComponent <Toggle>().isOn = false; } // food suits enabled if (System.Boolean.TryParse(PlayerPrefs.GetString(PlayerPrefKeys.foodSuitsEnabledKey), out isOn)) { foodSuitsToggle.GetComponent <Toggle>().isOn = isOn; } else { // unable to parse foodSuitsToggle.GetComponent <Toggle>().isOn = false; } lockout = false; }