【发布时间】:2020-05-11 07:17:59
【问题描述】:
我有一个关于我的 android 手机游戏的 playerprefs 没有正确初始化的问题。我已经在一个值为 3 的变量上预先设置了我的 playerprefs 数据。在我的统一播放模式中,该值通过我编写脚本的文本网格显示为 3。但是当我在我的 android 移动设备上安装和测试它时,它是 0。有人可以帮助如何在 android 平台上将我的 playerprefs 数据正确初始化为正确的值吗?
public static Game GM;
int maxAntiBody;
public TextMeshProUGUI antibodyTexMesh;
void Start () {
if (GM == null)
{
GM = this;
}
maxAntiBody = PlayerPrefs.GetInt("MaxAntiBody");
antibodyTexMesh.text = maxAntibody.toString();
}
void Update () {
debugging();
}
//I use this method for setting or resetting my desired value for the
playerprefs data I'm working with. In this case I choose 3 as a value.
void debugging() {
if (Input.GetKeyDown(KeyCode.M))
{
PlayerPrefs.SetInt("MaxAntiBody", plus++);
Debug.Log("max anti body value is : " +
PlayerPrefs.GetInt("MaxAntiBody"));
}
else if (Input.GetKeyDown(KeyCode.R))
{
plus = 0;
PlayerPrefs.SetInt("MaxAntiBody", plus);
Debug.Log("max anti body is now reseted to : " +
PlayerPrefs.GetInt("MaxAntiBody"));
}
}
【问题讨论】:
-
快速提醒; playerprefs 存储在设备上 - 因此您在 Windows 上的编辑器中所做的更改会存储到磁盘上的某个文件夹中。您的 android 设备将没有该文件 - 因此每个环境的更改都是唯一的
标签: c# unity3d game-engine