Advertisement
ssunlimited

Saving and Loading Syntax for Unity C#

Jul 4th, 2022
1,363
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void SaveGame()
  2.     {
  3.         GameInfo GI = new GameInfo();
  4.         BinaryFormatter bf = new BinaryFormatter();
  5.         FileStream file = File.Create(Application.persistentDataPath + "/gamesave.save");
  6.         bf.Serialize(file, GI);
  7.         file.Close();
  8.     }
  9.     public void LoadGame()
  10.     {
  11.         BinaryFormatter bf = new BinaryFormatter();
  12.         FileStream file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
  13.         GameInfo GI = (GameInfo)bf.Deserialize(file);
  14.         file.Close();
Advertisement
RAW Paste Data Copied
Advertisement