public bool Load() { try { if (File.Exists(Url)) { using (FileStream fileStream = File.Open(Url, FileMode.Open)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); PlayerDataExample data = (PlayerDataExample)binaryFormatter.Deserialize(fileStream); id = data.Id; playerName = data.Name; score = data.Score; skills = data.Skills; return(true); } } return(false); } catch (Exception ex) { Debug.LogError(ex.Message); return(false); } }
public bool Save() { try { using (FileStream fileStream = File.Create(Url)) { PlayerDataExample data = new PlayerDataExample(id, playerName, score, skills); BinaryFormatter binaryFormater = new BinaryFormatter(); binaryFormater.Serialize(fileStream, data); return(File.Exists(Url)); } } catch (Exception ex) { Debug.LogError(ex.Message); return(false); } }