Game Development Reference
In-Depth Information
If it does not, then we will continue to use the filename we previously set in our public
variable.
After this, we check whether our file already exists. If it does, we run a function that
will delete that file; we will create this function later on in this chapter. We delete the
file so that we don't have any issues with duplicate files or incorrect filenames being
made.
Next, we start the process of creating and saving our file. To do this, we use a
StreamWriter type. StreamWriter allows us to write data to a file. We use a ba-
sic instance of StreamWriter , but the class also has other options that can expand
upon how you write your data.
To use StreamWriter , we set the path that we want to write to, or in this case, the
stream, and then add lines to that stream that will be written to our file. To add lines
to our file, we call the native WriteLine function from the StreamWriter class.
Within this call, we pass the variable that we want to save. For this instance, we grab
PlayerPrefs we had set earlier as well as the player's transform position.
Search WWH ::




Custom Search