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

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return 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); } }