使用 playerprefs 在 Unity 中保存 int [英] Saving int in Unity using playerprefs

查看:48
本文介绍了使用 playerprefs 在 Unity 中保存 int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当玩家退出应用程序时,我需要保存 3 个整数.我想使用 playerprefs 保存它们,并且我需要它们能够在运行时被其他脚本更改.谁能给出一个代码示例,说明如何使用 playerprefs 进行保存以及如何在 int 更改时更新保存?

I have 3 ints that I need to save when the player quits the application. I want to save them using playerprefs and I need them to be able to be changed by other scripts during runtime. Can anyone give a code example of how to save with playerprefs and how to update the save when the ints are changed?

推荐答案

你这样保存

PlayerPrefs.SetInt("Health", 100);
PlayerPrefs.SetInt("Mana", 10);
PlayerPrefs.Save();

如果您想更新值,只需执行相同操作即可.要从 playerprefs 获取 int,只需执行

If you want to update the values, just do the same. To get a int from playerprefs, just do

PlayerPrefs.GetInt("Health")

这篇关于使用 playerprefs 在 Unity 中保存 int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆