本文介绍了PlayerPrefs不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,所以我正在尝试使用unitys Playerprefs方法以及它如何无法保存硬币,当我关闭并退出游戏时,它将无法保存...
Hey so im trying out unitys Playerprefs method and some how it wont save coins and when i close and exit the game it wont save it...
public Text CoinsText;
public int Coins;
public int clicks;
void Start()
{
PlayerPrefs.GetInt("Coins", Coins);
}
void Update()
{
CoinsText.text = "Memes: " + Coins;
if (Input.GetMouseButtonDown(0))
{
PlayerPrefs.SetInt("Coins", Coins);
Coins += clicks;
}
}
}
推荐答案
您永远不会分配硬币.
在您的Start()中尝试一下:
Try this in your Start():
Coins = PlayerPrefs.GetInt("Coins");
请注意,只有在没有保存值的情况下,第二个值.
Note that the second value is only in case there wouldn't be a value saved.
public static int GetInt(string key, int defaultValue = 0);
此外,在关闭程序之前,请不要忘记保存所有值:
Also, don't forget to Save all values before closing the program with:
PlayerPrefs.Save();
这篇关于PlayerPrefs不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!