What's wrong with my scorescript?
My score system worked perfectly before when I had three different scenes but when I incorporated my game over scene into my Level scene my score system broke. Before in the game over screen it showed my highscore and latest score now it shows what seems to be a random score when my game over screen fades over my level scene. This is my scoresystem script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreSystem : MonoBehaviour
{
public Text ScoreText;
private int Score;
void Start()
{
Score = 0;
SetScoreText();
}
public void IncreaseScore()
{
{
Score = Score + 1;
SetScoreText();
}
}
public void SetScoreText()
{
ScoreText.text = "" + Score.ToString();
}
void Update()
{
if (Score > PlayerPrefs.GetInt("Highscore"))
{
PlayerPrefs.SetInt("Highscore", Score);
}
else
if (Score <= PlayerPrefs.GetInt("Highscore"))
{
PlayerPrefs.SetInt("LatestScore", Score);
}
}
}
This is my score script which should show what score the player has recently got before losing:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreScript : MonoBehaviour
{
public Text Latest;
void Awake()
{
Latest.text = "Score: " + PlayerPrefs.GetInt("LatestScore");
}
}
Your answer
Follow this Question
Related Questions
How do I add my Timer to my Score system in C# ? 0 Answers
How to save highscores 1 Answer
PlayerPrefs not working on android 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers
Help with 2D platformer (score),For my 2D game sometimes coins get added twice to the score?! 0 Answers