为什么 PlayerPrefs.GetInt() 不统一不起作用?
Why isn't PlayerPrefs.GetInt() in unity not working?
我正在做一个项目,我想制作一个记分牌场景,但在开始之前,我想知道并理解 PlayerPrefs.GetInt()
是什么。看了api后,我做了一个测试,看看它是否有效。我转到 windows 上的注册表编辑器,转到我的项目并添加了一个名为 Player Name 的新字符串值,我附加了一个 int
值 20,仅用于测试。我创建了一个名为 number
的 int
变量,并将其设为 public
,这样当我 运行 unity 时,我可以看到它附加了什么值。这是我的脚本:
public int number;
void Start() {
number = PlayerPrefs.GetInt ("Player Name", 10);
}
出于某种原因,number
后面的唯一数字是 10。为什么?我将衷心感谢您的帮助。有什么问题可以直接问。
I went to the registry editor on windows, went to my project and added
a new string value called Player Name
这是错误的。您不从注册表中设置 PlayerPrefs。您使用 PlayerPrefs.SetInt
保存它并使用 PlayerPrefs.GetInt
阅读它。
保存:
PlayerPrefs.SetInt("Player Name", 20);
PlayerPrefs.Save();
阅读:
int number = PlayerPrefs.GetInt("Player Name", 20);
我正在做一个项目,我想制作一个记分牌场景,但在开始之前,我想知道并理解 PlayerPrefs.GetInt()
是什么。看了api后,我做了一个测试,看看它是否有效。我转到 windows 上的注册表编辑器,转到我的项目并添加了一个名为 Player Name 的新字符串值,我附加了一个 int
值 20,仅用于测试。我创建了一个名为 number
的 int
变量,并将其设为 public
,这样当我 运行 unity 时,我可以看到它附加了什么值。这是我的脚本:
public int number;
void Start() {
number = PlayerPrefs.GetInt ("Player Name", 10);
}
出于某种原因,number
后面的唯一数字是 10。为什么?我将衷心感谢您的帮助。有什么问题可以直接问。
I went to the registry editor on windows, went to my project and added a new string value called Player Name
这是错误的。您不从注册表中设置 PlayerPrefs。您使用 PlayerPrefs.SetInt
保存它并使用 PlayerPrefs.GetInt
阅读它。
保存:
PlayerPrefs.SetInt("Player Name", 20);
PlayerPrefs.Save();
阅读:
int number = PlayerPrefs.GetInt("Player Name", 20);