У меня есть 3 сцены: Меню, Игра и GameOver. Когда я запускаю сцену меню, я запускаю этот скрипт, прикрепленный к основной камере:
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class prefs : MonoBehaviour
{
public static int bestRecord;
// Start is called before the first frame update
void Start()
{
bestRecord = PlayerPrefs.GetInt("K", 1);
Debug.Log(PlayerPrefs.GetInt("K").ToString());
}
}
Код: Выделить всё
public TextMeshProUGUI points;
void Start()
{
stop = false;
InvokeRepeating("subirMetros", 0f, 0.01f);
}
private void subirMetros()
{
if (stop == false)
{
points.SetText(Math.Round(character.transform.position.x, 0) + "");
}
}
//GameOver is called when the player dies
public void GameOver()
{
stop = true;
CancelInvoke("subirMetros");
int finalPoints = Int32.Parse(points.text);
int recordActual = PlayerPrefs.GetInt("K");
if (recordActual < finalPoints)
{
PlayerPrefs.SetInt("K", finalPoints);
}
SceneManager.LoadScene("GameOver");
}
}
Код: Выделить всё
public TextMeshProUGUI record;
void Start()
{
record.text = PlayerPrefs.GetInt("K").ToString();
}
Подробнее здесь: https://stackoverflow.com/questions/606 ... t-in-build