溫馨提示×

unity怎么刪除本地文件

小億
418
2024-02-19 11:01:24
欄目: 編程語言

要刪除本地文件,可以使用Unity的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");
        }
    }
}

在上面的示例代碼中,首先設置了要刪除的文件的路徑,然后檢查文件是否存在,如果存在則調用File.Delete()方法來刪除文件。最后在控制臺輸出相應的信息。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女