Delete Local File in Unity Guide
To delete a local file, you can use Unity’s File class to manipulate the file. Below is an example code for deleting a local file:
using System.IO;
using UnityEngine;
public class DeleteFile : MonoBehaviour
{
void Start()
{
string filePath = "path_to_your_file"; // 设置文件路径
if (File.Exists(filePath))
{
File.Delete(filePath); // 删除文件
Debug.Log("File deleted successfully");
}
else
{
Debug.LogError("File not found");
}
}
}
In the example code above, the path of the file to be deleted is first set, then the existence of the file is checked, and if it exists, the File.Delete() method is called to delete the file. Finally, the corresponding information is displayed on the console.