我在Android上遇到PlayerPrefs问题。我希望我的教程只显示一个时间,所以我写了这个代码:PlayerPrefs不适用于Android或编辑器
void Awake(){
firstTime = false;
hasPlayed = PlayerPrefs.GetInt ("hasPlayed");
if (hasPlayed == 0) {
firstTime = true;
} else {
PlayerPrefs.SetInt ("hasPlayed", 1);
firstTime = false;
PlayerPrefs.Save();
}
}
一旦建成,并在手机测试中,APK不会创建任何文件夹/数据或什么的,因此,将教程每次展示我运行游戏。
尝试登录hasPlayed'的'值。你也可以尝试在'GetInt(“hasPlayed”,0)中添加第二个参数;'确保你得到0作为默认值。 –
你只是忘了GetInt上的“,0” – Fattie