PlayerPrefs.GetFloat
Declaration
public static float GetFloat(string key);Параметры
| Параметр | Описание |
|---|---|
| ключ | Ключ, используемый для получения соответствующего значения float в настройках игрока. |
Возвращаемое значение
поплавок Значение с плавающей запятой, соответствующее заданной key. Возвращает 0,0f, если для заданной keyне найдено значения с плавающей запятой.
Описание
Возвращает значение с плавающей запятой, которое соответствует key в настройках игрока.
Возвращает 0.0f, если для заданного keyне найдено значения с плавающей запятой.
//Use this script to get the PlayerPrefs settings and display them as text on the screen.
using UnityEngine;
public class PlayerPrefsGetFloatExample : 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"); }
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); } }
Declaration
public static float GetFloat(string key, float defaultValue);Параметры
| Параметр | Описание |
|---|---|
| ключ | Ключ, используемый для получения соответствующего значения float в настройках игрока. |
| defaultValue | Значение, которое возвращается, когда не найдено значения с плавающей запятой для key в настройках игрока. |
Возвращаемое значение
поплавок Значение с плавающей запятой, соответствующее заданной key. Возвращает defaultValue, если для заданной keyне найдено значения с плавающей запятой.
Описание
Получает значение с плавающей запятой, соответствующее key в настройках игрока.
Возвращает заданные defaultValue, если не найдено значения с плавающей запятой для заданных key.
//Use this script to fetch the PlayerPrefs settings and show them as text on the screen.
using UnityEngine;
public class PlayerPrefsGetFloatWithDefaultValueExample : 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 100. m_Health = PlayerPrefs.GetFloat("Health", 100); }
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); } }