- Home /
how to creat and scoring and high score system for an endless runner,how do I display my score on a game over scene and also create and high score system for the same ?
I have created this endless runner where the player have to dodge obstacles for earning points and for scoring system I have create a score manager script which is placed on back of the screen . I am able to display my score on the main screen using UI. but I want to display the score on a game over scene and also create a high score system on the game over scene.Also created public static to save the data even though it saved my data and displayed it on the game over scene but when I restarted my game the score did not start at 0 but it was the continuation of the last game score. please help me HERE IS THE SCORE MANAGER SCRIPT OF MY GAME using UnityEngine; using UnityEngine.UI;
public class ScoreManager : MonoBehaviour { public static int score = 0; public Text scoreDisplay;
public void Update() { scoreDisplay.text = score.ToString(); }
void OnTriggerEnter2D(Collider2D other) { if(other.CompareTag("Obstacle")) { score++; Debug.Log(score); } }
},I have create an endless runner where the player moves back and forth and dodges obstacles . and for scoring I have set a score manager on back of the scene and changed the tag of the obstacle. I want to show the score on a different game over scene where I will show the current score and also have a high scoring system for the same. I also used private static the score gets saved to the next scene but the when I restart the game the score is loaded from the score last game score. please help me .. HERE IS THE CODE OF MY ScoreManager using UnityEngine; using UnityEngine.UI;
public class ScoreManager : MonoBehaviour { public static int score = 0; public Text scoreDisplay;
public void Update() { scoreDisplay.text = score.ToString(); }
void OnTriggerEnter2D(Collider2D other) { if(other.CompareTag("Obstacle")) { score++; Debug.Log(score); } }
}