O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading our flat files

For the final feature in our flat file system, we add the loading functionality.

Time to load our file

Now that we have created a way to save information to a flat file, we need to create a way to load that information. To do this, we will use a similar process as the one that we used to save the information. Let's add our final function to the script:

void ReadFile(string file = "") { if(file != "") sFileName = file; using(StreamReader sr = new StreamReader(sDirectory + sFileName)) { int kills = Convert.ToInt32(sr.ReadLine()); int deaths = Convert.ToInt32(sr.ReadLine()); int totgold = Convert.ToInt32(sr.ReadLine()); int curgold = Convert.ToInt32(sr.ReadLine()); int level = Convert.ToInt32(sr.ReadLine()); int rwon = Convert.ToInt32(sr.ReadLine()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required