okay so the errors i have are:
-
it will save but won’t load
-
i have an error while trying to call out the functions(using corgi engine) such as:
-
Assets/Resource/Scripts/SaveManager.cs(13,12): error CS0246: The type or namespace name `MaximumHealth’ could not be found. Are you missing an assembly reference?
-Assets/Resource/Scripts/SaveManager.cs(12,12): error CS0246: The type or namespace name `IntialHealth’ could not be found. Are you missing an assembly reference?
- Assets/Resource/Scripts/SaveManager.cs(11,12): error CS0246: The type or namespace name `DamageCaused’ could not be found. Are you missing an assembly reference?
also this is the script i used
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class SaveManager : MonoBehaviour {
public int PointsText;
public Transform Player1;
public DamageCaused damageCaused;
public IntialHealth health;
public MaximumHealth maximumHealth;
public static List<SaveGame> savedGames = new List<SaveGame>();
public void SaveGame()
{
PlayerPrefs.SetInt("Points", PointsText);
PlayerPrefs.SetInt("HP", health);
PlayerPrefs.SetInt("MHP", maximumHealth);
PlayerPrefs.SetInt("Damage", damageCaused);
PlayerPrefs.SetFloat("Player1PosX", Player1.position.x);
PlayerPrefs.SetFloat("Player1PosY", Player1.position.y);
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");
bf.Serialize(file, SaveManager.savedGames);
file.Close();
Debug.Log("Saving...");
}
public void LoadGame()
{
if (File.Exists(Application.persistentDataPath + "/savedGames.gd"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open);
SaveManager.savedGames = (List<SaveGame>)bf.Deserialize(file);
file.Close();
Debug.Log("Loading...");
}
}
}
If you are using corgi engine and DamageCaused, InitialHealth, MaximumHealth are part of it, you probably need the proper using statement at the top.
Assuming you spelled the class names correctly when declaring your variables, you should be able to right click the name (like DamageCaused) and there should be a lightbulb. Click it and there should be an option for a using statement to resolve it.
Otherwise, you’ll need to know what using you need to declare at the top. I don’t use Corgi, so I couldn’t tell you what it is.
i fixed it
thanks but now the problem i have is i can save but can’t load… Here are the C# scripts
SaveManager:
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
namespace MoreMountains.CorgiEngine
{
public class SaveManager : MonoBehaviour
{
public static SaveManager current;
internal static List<SaveManager> savedGames;
public int PointsText;
public Transform Player1;
public int DamageCaused = 10;
public int CurrentHealth;
public int MaximumHealth;
public void SaveGame()
{
PlayerPrefs.SetInt("Points", PointsText);
PlayerPrefs.SetFloat("HP", CurrentHealth);
PlayerPrefs.SetInt("MHP", MaximumHealth);
PlayerPrefs.SetInt("Damage", DamageCaused);
PlayerPrefs.SetFloat("Player1PosX", Player1.position.x);
PlayerPrefs.SetFloat("Player1PosY", Player1.position.y);
Debug.Log("Saving...");
}
}
}
LoadManager:
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
namespace MoreMountains.CorgiEngine
{
public class LoadManager : MonoBehaviour
{
public static List<SaveManager> savedGames = new List<SaveManager>();
public void Saved()
{
LoadManager.savedGames.Add(SaveManager.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");
bf.Serialize(file, SaveManager.savedGames);
Debug.Log("Saving...");
file.Close();
}
public void LoadGame()
{
if (File.Exists(Application.persistentDataPath + "/savedGames.gd"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open);
SaveManager.savedGames = (List<SaveManager>)bf.Deserialize(file);
file.Close();
Debug.Log("Loading...");
}
}
}
}
for some reason copying and pasting the code into the forums mess up the structure 