when you get a score and you reaload the scene it will be back at 0 so my highscore will stay at 0. how do i fix it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SocialPlatforms.Impl;
public class ScoeScript : MonoBehaviour
{
public static int scoreValue = 0;
public TextMeshProUGUI Score;
public Text Highscore;
// Start is called before the first frame update
void Start()
{
Score = GetComponent<TextMeshProUGUI>();
Highscore.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
}
// Update is called once per frame
void Update()
{
Score.text = "Score: " + scoreValue;
Highscore.text = scoreValue.ToString();
if(scoreValue > PlayerPrefs.GetInt("HighScore", 0))
{
PlayerPrefs.SetInt("HighScore", scoreValue);
}
}
}