Advertisement
evelynshilosky

MainMenuSaveManager (Name is SaveManager to save time in next episode) - Part 22

Nov 2nd, 2023 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SaveManager : MonoBehaviour
  6. {
  7.     public static SaveManager Instance { get; set; }
  8.     private void Awake()
  9.     {
  10.         if (Instance != null && Instance != this)
  11.         {
  12.             Destroy(gameObject);
  13.         }
  14.         else
  15.         {
  16.             Instance = this;
  17.         }
  18.  
  19.         DontDestroyOnLoad(gameObject);
  20.  
  21.     }
  22.  
  23.    
  24.     [System.Serializable]
  25.     public class VolumeSettings
  26.     {
  27.         public float music;
  28.         public float effects;
  29.         public float master;
  30.     }
  31.  
  32.     public void SaveVolumeSettings(float _music, float _effects, float _master)
  33.     {
  34.         VolumeSettings volumeSettings = new VolumeSettings()
  35.         {
  36.             music = _music,
  37.             effects= _effects,
  38.             master = _master
  39.         };
  40.  
  41.         PlayerPrefs.SetString("Volume", JsonUtility.ToJson(volumeSettings));
  42.         PlayerPrefs.Save();
  43.  
  44.         print("Saved to Player Pref");
  45.     }
  46.  
  47.     public VolumeSettings LoadVolumeSettings()
  48.     {
  49.         return JsonUtility.FromJson<VolumeSettings>(PlayerPrefs.GetString("Volume"));
  50.     }
  51.  
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement