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

Deleting our flat files

Next, we create a function that allows us to delete flat files. Add this function to your script:

void DeleteFile(string file = "")
{
  File.Delete(sDirectory + file);
}

To delete a file, we use the Delete function within the File class. Before we delete the file, we make sure that it actually exists using the Exists function within the File class. The file that we are deleting is the one that is set to our directory and filename variables.

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