问题描述
我在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
之后.那可能会解决您的问题.
Call PlayerPrefs.Save
after PlayerPrefs.SetInt
. That will likely solve your problem.
void OnApplicationQuit()
{
PlayerPrefs.SetInt("numerator", numerator);
PlayerPrefs.Save();
}
如果这不能解决您的问题,请在 OnApplicationPause
中执行保存操作或OnDisable
函数.
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上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!