Version: 2018.2
public static float GetFloat (string key);
public static float GetFloat (string key, float defaultValue);

説明

キーが存在する場合、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); } }