设置由给定键标识的该首选项的浮点值。可以使用PlayerPrefs.GetFloat来检索此值。
以下示例将KeyName和Value 变量传递给名为SetFloat的函数。函数使用PlayerPrefs.SetFloat中的KeyName变量作为标识符,并将Value用作要存储的内容。例如,可以使用PlayerPrefs.SetFloat来存储用户的当前健康状况,如下所示:/PlayerPrefs.SetFloat(“CharacterHealth”, 60.5f)/。GetFloat 函数随后使用相同的KeyName变量来检索存储在PlayerPrefs中的值。有关详细信息,请参阅PlayerPrefs.GetFloat。
using UnityEngine;
public class Example : MonoBehaviour { public void SetFloat(string KeyName, float Value) { PlayerPrefs.SetFloat(KeyName, Value); }
public float GetFloat(string KeyName) { return PlayerPrefs.GetFloat(KeyName); } }