首页 > 解决方案 > 如何找到正确的路径以统一保存数据

问题描述

我有一个游戏。每当最终用户退出时,我都应该保存游戏。如何知道在哪里保存?因为如果我将游戏保存到C://Users/..路径下,如果用户使用AndroidIOS会发生什么?这个问题的解决方案是什么?

标签: c#unity3dsave

解决方案


使用根据平台变化的应用程序数据文件夹。

//Attach this script to a GameObject
//This script outputs the Application’s path to the Console
//Run this on the target device to find the application data path for the platform
using UnityEngine;

public class Example : MonoBehaviour
{
    string m_Path;

    void Start()
    {
        //Get the path of the Game data folder
        m_Path = Application.dataPath;

        //Output the Game data path to the console
        Debug.Log("dataPath : " + m_Path);
    }
}

在这里阅读更多关于它的信息


推荐阅读