BinaryWriter writes typed values to a stream as a continuous sequence of bytes. Reading them back requires using the same order as writing. section 7.1.1
Saving enemy data
Write an enemy count as an integer, then write each enemy position’s x and y values. Read the values back in that same order. section 7.1.1
Listing 7.5 Writing data in binary
string fileName = Application.persistentDataPath + "/DODSurvivor/gamedata.dat";
using (FileStream fs = File.Create(fileName))
using (BinaryWriter bw = new BinaryWriter(fs))
{
int numEnemies = gameData.EnemyPosition.Length;
bw.Write(numEnemies);
}A Unity save-file example creates a FileStream, wraps it in BinaryWriter, and writes the enemy count. section 7.1.1
