Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO;
  5. using System;
  6.  
  7. public class SaveLoad : MonoBehaviour
  8. {
  9.     private Save sv = new Save();
  10.     private string path;
  11.     public int ss;
  12.    
  13.    
  14.     private void Start()
  15.  
  16.     {
  17. #if UNITY_ANDROID && !UNITY_EDITOR
  18.         path = Path.Combine(Application.persistenDataPath, "Save.json");
  19. #else
  20.         path = Path.Combine(Application.persistentDataPath, "Save.json");
  21. #endif
  22.  
  23.         if (File.Exists(path))
  24.         {
  25.             sv = UnityEngine.JsonUtility.FromJson<Save>(File.ReadAllText(path));
  26.             Debug.Log(sv.score);
  27.  
  28.             ss = sv.score;
  29.         }
  30.     }
  31.     public void Update()
  32.     {
  33.  
  34.         GetComponent<Money>().vov(ss);
  35.     }
  36.     public void Ggdrop(int gkf)
  37.     {
  38.         ss = gkf;
  39.  
  40.         sv.score = ss;
  41.     }
  42.  
  43. #if UNITY_ANDROID && !UNITY_EDITOR
  44.     private void OnApplicationPause(bool pause)
  45.     {
  46.     if (pause) File.WriteAllText(path, JsonUtilly.ToJson(sv));
  47.    
  48.     }
  49. #endif
  50.     private void OnApplicationQuit()
  51.     {
  52.         File.WriteAllText(path, UnityEngine.JsonUtility.ToJson(sv));
  53.     }
  54.  
  55.  
  56. }
  57.  [Serializable]
  58.  public class Save
  59. {
  60.     public int score ;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement