返回偏好设置文件中与 key
对应的值(如果存在)。
如果不存在,则返回 /defaultValue/。
//Use this script to fetch the PlayerPrefs settings and show them as text on the screen.
using UnityEngine; using UnityEngine.UI;
public class PlayerPrefsDeleteAllExample : MonoBehaviour { float m_Health;
void Start() { //Fetch the PlayerPref settings SetText(); }
void SetText() { //Fetch the health from the PlayerPrefs (set these Playerprefs elsewhere). If no float of this name exists, the default is 0 m_Health = PlayerPrefs.GetFloat("Health", 0); }
void OnGUI() { //Fetch the PlayerPrefs settings and output them to the screen using Labels GUI.Label(new Rect(50, 90, 200, 30), "Health : " + m_Health); } }