PlayerPrefs 未在 Android 上保存 [英] PlayerPrefs not saving on Android

查看:34
本文介绍了PlayerPrefs 未在 Android 上保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 unity3d 5.4 中遇到了 PlayerPrefs 的一些问题.(我使用 5.4,因为 5.5 中有一个破坏游戏的错误.)

I ran into a bit of a problem with PlayerPrefs in unity3d 5.4. (I am using 5.4 because there is a game-breaking bug in 5.5.)

代码如下:

void OnApplicationQuit() {
    PlayerPrefs.SetInt("numerator", numerator);
}

这在编辑器中运行良好,但在移动设备上则是另一回事.它没有任何作用.

This works fine in the editor, but on mobile it's a different story. It doesn't do anything.

推荐答案

调用 PlayerPrefs.SetInt 之后的 >PlayerPrefs.Save.这可能会解决您的问题.

Call PlayerPrefs.Save after PlayerPrefs.SetInt. That will likely solve your problem.

void OnApplicationQuit()
{
    PlayerPrefs.SetInt("numerator", numerator);
    PlayerPrefs.Save();
}

如果这不能解决您的问题,请在 中执行保存操作OnApplicationPauseOnDisable 函数.

If that does not solve your problem, do the save operation in the OnApplicationPause or OnDisable function.

void OnApplicationPause(bool pauseStatus)
{
    if (pauseStatus)
    {
        PlayerPrefs.SetInt("numerator", numerator);
        PlayerPrefs.Save();
    }
}

如果这两个都失败了,请查看此处了解如何使用 Json 保存和加载游戏数据.

If both of these fail, Please look here for how to use Json to save and load game data.

这篇关于PlayerPrefs 未在 Android 上保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆