I have error in my game saving script (C#).

this is error: Assets/Scripts/LoadGame.cs(48,2): error CS0246: The type or namespace name `serializable’ could not be found. Are you missing a using directive or an assembly reference?

I want to know what’s wrong.

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
public class LoadGame : MonoBehaviour
{
	public Turn turn;

	
	public void Save()
	{
		BinaryFormatter bf = new BinaryFormatter();
		FileStream file = File.Create(Application.persidentDataPath + "/playerInfo.dat");

		PlayerData data = new PlayerData();
		turn.Cash = Cash;

		bf.Serialize(file, data);
		file.Close();
	}
	public void Load() 
	{
		if (File.Exists(Application.persidentDataPath + "/playerInfo.dat")) 
		{
			BinaryFormatter bf = new BinaryFormatter();
			FileStream file = File.Open(Application.persidentDataPath + "/playerInfo.dat", FileMode.Open);
			file.Close();

			Cash = turn.Cash;
		}
	}
}

[serializable]
class PlayerData 
{
	public int Cash;
}

isn't it Serializable? also, it looks like the closing brace on line 9 shouldn't be there...

1 Answer

1

Most computer languages are case sensitive, meaning serializable and Serializable aren’t the same thing. The attribute in this case is Serializable.

Now I have this error Assets/Scripts/LoadGame.cs(27,17): error CS0246: The type or namespace name `FileStream' could not be found. Are you missing a using directive or an assembly reference?

when i'm using system.IO; many errors appear.