Game Development Reference
In-Depth Information
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.IO;
using System.Text;
For this script, we will only need to create a few public variables; add these to your
script:
public string sFileName;
public string sDirectory;
public GameObject Player;
The first string will be the file that we will save and load from will be called, the name
should also include the extension. The next string is the directory that we will save
to and load from—for testing purposes and using the Desktop directory so that we
can easily find it later on. Our final variable, GameObject , is our player.
Time to save our file
Now, we will add the function that will allow us to save our flat file. To save our file,
we will use the code that we didn't discuss in this topic before, as you can see from
our new using statements. Add this function to your script:
void WriteToFile(string file = "")
{
if(file != "")
sFileName = file;
if(File.Exists(sDirectory + sFileName))
{
DeleteFile(sFileName);
}
Search WWH ::




Custom Search