- Home /
Regarding reset the state to the first time we start to play
Hi, first of all thanks for anyone who willing to read this question... First i will explain that I have a game which utilize save and load with this code SaveLoad public class SaveLoad {
public static List<Game> savedGames = new List<Game> ();
public static void Save(){
savedGames.Add (Game.current);
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + "/savedGames.dat");
bf.Serialize (file, SaveLoad.savedGames);
file.Close ();
}
public static void Load(){
if (File.Exists(Application.persistentDataPath + "/savedGames.dat")){
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/savedGames.dat", FileMode.Open);
SaveLoad.savedGames = (List<Game>)bf.Deserialize (file);
file.Close ();
}
}
}
The Game Class and Character Class [System.Serializable] public class Game {
public static Game current;
public Character game1;
public Character game2;
public Game()
{
game1 = new Character ();
}
}
public class Character{
public int Lv;
public int Xp;
public float positionX;
public float postiionY;
public int Atk;
public int Hp;
public int Def;
public Character()
{
this.Lv = PlayerStats.Pstat.currentLvl;
this.Xp = PlayerStats.Pstat.currentExp;
this.positionX = PlayerMovement.PMov.lastmoving.x;
this.postiionY = PlayerMovement.PMov.lastmoving.y;
this.Atk = PlayerStats.Pstat.curAtk;
this.Hp = PlayerStats.Pstat.curHp;
this.Def = PlayerStats.Pstat.curDef;
}
}
And the script for the button which holding save and load public void SaveGame() { SaveLoad.Save (); Debug.Log ("Game Saved"); }
public void LoadGame()
{
SaveLoad.Load ();
foreach (Game g in SaveLoad.savedGames)
{
Game.current = g;
Debug.Log ("Game Loaded");
SceneManager.LoadScene("Home");
}
}
Now my problem is when I got a game over and the UI out then return to main menu, when I hit my load and play button they would return to the state where the game over UI was out and can't be played anymore... Is there a way to solve this? Like resetting the state or something like that... And even when I just load the game before getting the game over, the pause UI would appear suddenly as well...
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Save load custom class values not assigned object null reference 1 Answer
How to reset timer? (C#) 3 Answers
How to create a save & load system with: System.Serializable ??? 1 Answer