Unity 6.3
0 онлайн 34 гостей 3 в системе
Вход

PlayerPrefs.GetInt

Declaration

public static int GetInt(string key);

Параметры

Параметр Описание
ключ Ключ, используемый для получения соответствующего значения int в настройках проигрывателя.

Возвращаемое значение

инт Значение int, соответствующее заданной key. Возвращает 0, если для заданной keyне найдено значения int.

Описание

Получить int значение, которое соответствует key в настройках проигрывателя.

Возвращает 0, если для заданного keyне найдено интегрального значения.

//Use this script to fetch the settings and show them as text on the screen.

using UnityEngine;

public class PlayerPrefsGetIntExample : MonoBehaviour { int m_Score;

void Start() { //Fetch the PlayerPref settings SetText(); }

void SetText() { //Fetch the score from the PlayerPrefs (set these PlayerPrefs in another script). If no Int of this name exists, the default is 0. m_Score = PlayerPrefs.GetInt("Score"); }

void OnGUI() { //Fetch the PlayerPrefs settings and output them to the screen using Labels GUI.Label(new Rect(50, 130, 200, 30), "Score : " + m_Score); } }

Declaration

public static int GetInt(string key, int defaultValue);

Параметры

Параметр Описание
ключ Ключ, используемый для получения соответствующего значения int в настройках проигрывателя.
defaultValue Значение, которое возвращается, когда не найдено интегрального значения для key в настройках игрока.

Возвращаемое значение

инт Значение int, соответствующее заданной key. Возвращает defaultValue, если для заданной keyне найдено значения int.

Описание

Получить int значение, которое соответствует key в настройках проигрывателя.

Возвращает заданные defaultValue, если не найдено интегрального значения для заданных key.

//Use this script to fetch the settings and show them as text on the screen.

using UnityEngine;

public class PlayerPrefsGetIntExample : MonoBehaviour { int m_Score;

void Start() { //Fetch the PlayerPref settings SetText(); }

void SetText() { //Fetch the score from the PlayerPrefs (set these PlayerPrefs in another script). If no Int of this name exists, the default is 100. m_Score = PlayerPrefs.GetInt("Score", 100); }

void OnGUI() { //Fetch the PlayerPrefs settings and output them to the screen using Labels. GUI.Label(new Rect(50, 130, 200, 30), "Score : " + m_Score); } }