Quantcast
Channel: Latest Questions by honikun
Viewing all articles
Browse latest Browse all 49

Problem to add a delete method to a saveload script C#

$
0
0
I have this SaveLoad code and i'm trying to make a delete funtion, tried to use SaveLoad.SavedGames.remove = game.current; but not worked, can someone help me? The script just create a file with player names, i know how to delete the file, but i want to delete just one player, by this i mean, just one string from the saved file. here is my code: using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization.Formatters.Binary; using System.IO; public static class SaveLoad { public static List savedGames = new List(); //it's static so we can call it from anywhere public static void Save() { SaveLoad.savedGames.Add(Game.current); BinaryFormatter bf = new BinaryFormatter(); //Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located FileStream file = File.Create (Application.persistentDataPath + "/savedGames.gd"); //you can call it anything you want bf.Serialize(file, SaveLoad.savedGames); file.Close(); } public static void Load() { if(File.Exists(Application.persistentDataPath + "/savedGames.gd")) { Debug.Log(Application.persistentDataPath); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open); SaveLoad.savedGames = (List)bf.Deserialize(file); file.Close(); } } }

Viewing all articles
Browse latest Browse all 49

Trending Articles