1
我在unity3d 5.4中遇到了PlayerPrefs的一個問題。 (我使用的5.4,因爲在5.5遊戲破錯誤。)PlayerPrefs未在Android上保存
下面是代碼:
void OnApplicationQuit() {
PlayerPrefs.SetInt("numerator", numerator);
}
這正常的編輯器,但在移動這是一個不同的故事。它什麼都不做。
我在unity3d 5.4中遇到了PlayerPrefs的一個問題。 (我使用的5.4,因爲在5.5遊戲破錯誤。)PlayerPrefs未在Android上保存
下面是代碼:
void OnApplicationQuit() {
PlayerPrefs.SetInt("numerator", numerator);
}
這正常的編輯器,但在移動這是一個不同的故事。它什麼都不做。
撥打PlayerPrefs.Save
後PlayerPrefs.SetInt
。這可能會解決你的問題。
void OnApplicationQuit()
{
PlayerPrefs.SetInt("numerator", numerator);
PlayerPrefs.Save();
}
如果不解決您的問題,請在OnApplicationPause
或OnDisable
功能保存操作。
void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
PlayerPrefs.SetInt("numerator", numerator);
PlayerPrefs.Save();
}
}
如果這兩個失敗,請look這裏如何使用JSON來保存和載入遊戲數據。
謝謝! 'OnApplicationPause'和'PlayerPrefs.Save'一起訣竅! –