UNITY | PROJECT | 2D PlatFormer | 7. Save & Load

2
“EndLevel” | Sprite Renderer

 

5
“EndLevel” | “DataManagement” Script

 

 

3
“DataManagement” Script
  • in Awake() method,
  • create a function, SaveData(),
    • make a BinaryFormatter to serialize the data later
    • make a FileStream and File to create a path and the target file
    • create a container for the save data by creating another class in the script
      • put the data in it
      • serialize the data with the BinaryFormatter
      • Don’t Forget to close the file by using File.Close()
  • create a function, LoadData(),
    • make a BinaryFormatter to Deserialize the data later
    • make a FileStream and File to open the target file
    • Deserialize the data with the BinaryFormatter
    • Don’t Forget to close the file by using File.Close()

 

4
“PlayerScore()” Script
  • Create a function, CountScore()
    • show the current score with Debug.Log()
    • calculate the score
    • update the score
    • Save the Score by using SaveData() function from DataManagement Class
    • show the updated Score with Debug.Log()
  • in Start() function
    • put LoadData() function from DataManagement Class