Runner на Unity, не получается вытащить значения из реестра в другую сцену
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public int score = 0;
public static Score instance;
public Text scoretext;
private bool isdead = false;
public DeathMenu menu;
// Start is called before the first frame update
private void Start()
{
instance = this;
//ResetHigthscore();
}
// Update is called once per frame
void Update()
{
if (isdead)
return;
}
public void OnisDead()
{
isdead = true;
PlayerPrefs.SetFloat("Higth score", score);//сохраняю значение в реестр
PlayerPrefs.Save();
menu.TouchMenu(score);
}
public void IncreaseScore(int increment)
{
scoretext.text = ((int)score).ToString();
score += increment;
}
}
//скрипт другой сцены где загружаем значения из этого реестра
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainMenu : MonoBehaviour
{
public Text scoretext;
public static MainMenu menu;
// Start is called before the first frame update
void Start()
{
scoretext.text = "Higth score: " + ((int)PlayerPrefs.GetInt("Higth score")).ToString();
}
// Update is called once per frame
public void ToGame()
{
SceneManager.LoadScene("Level3");
}
}
Использую Windows7. В реестре видно что данные сохраняются, но не загружаются в сцену
Ответы (1 шт):
Автор решения: luvjungle
→ Ссылка
Вы сохраняете через SetFloat(), а получаете через GetInt(), так работать не будет.
Или SetFloat() и GetFloat() или SetInt() и GetInt()