Here is my code. I do not really know a lot about this kind of stuff, so I followed this Unity Tutorial: I am getting this error in my console, and It does not give a line number,
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class GameControl : MonoBehaviour {
public static GameControl control;
public float coins;
public bool[] levelsUnlocked;
void Awake () {
if(control == null){
DontDestroyOnLoad(gameObject);
control = this;
}else if(control != this){
Destroy(gameObject);
}
}
void Update () {
Save();
}
public void Save(){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = new PlayerData();
data.coins = coins;
data.levelsUnlocked = levelsUnlocked;
bf.Serialize(file, data);
file.Close();
}
public void Load(){
if(File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
coins =data.coins;
levelsUnlocked = data.levelsUnlocked;
}
}
}
[Serializable]
class PlayerData{
public float coins;
public bool[] levelsUnlocked;
}
Error Message
FileNotFoundException: Could not find file "C:\Users\Nathan\AppData\LocalLow\DefaultCompany\Number Game\playerInfo.dat"
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/FileStream.cs:320)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.File.Open (System.String path, FileMode mode) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:347)
GameControl.Save () (at Assets/Scripts/GameControl.cs:32)
GameControl.Update () (at Assets/Scripts/GameControl.cs:25)
Any help? Also, if there is a more “user-friendly” way to store a 91 long bool and an int, I would love to know how.