Доброго времени суток, подскажите пожалуйста как можно отобразить highscore в меню( на другой сцене)?
Есть такой скрипт, висит на игроке
public class PlayrMovement : MonoBehaviour
{
private Rigidbody2D playerRb;
public float speed = 3;
private static int score;
private static int highScore;
public event UnityAction ScoreChanged;
public event UnityAction HighScoreChanged;
private void Start()
{
playerRb = GetComponent();
playerRb.GetComponent().gravityScale = 0;
highScore = PlayerPrefs.GetInt("highScore", highScore);
}
private void Update()
{
if (Input.GetKey(KeyCode.W))
{
playerRb.transform.Translate(Vector2.up * speed * Time.deltaTime);
IncreaseScore();
}
if (Input.GetKey(KeyCode.S))
{
playerRb.transform.Translate(Vector2.down * speed * Time.deltaTime);
}
HighScoreMethod();
}
public void IncreaseScore()
{
ScoreChanged?.Invoke(score);
score++;
}
public void HighScoreMethod()
{
HighScoreChanged?.Invoke(highScore);
if (score > highScore)
{
highScore = score;
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
}
}
}
на UI висит это
public TextMeshProUGUI _highScoreText;
public PlayrMovement player;
private void OnEnable()
{
player.HighScoreChanged += OnHighScoreChanged;
}
private void OnDisable()
{
player.HighScoreChanged -= OnHighScoreChanged;
}
private void OnHighScoreChanged(int highScore)
{
_highScoreText.text = highScore.ToString();
Debug.Log("Work");
}