How do I make a Score and Highscore thingie in game over screen
(I started coding and using unity a few days ago) Like the title says, I want it to display my score and the highscore of that player. I can display the score in the game itself, but I dont know how to put it in the game over screen, let alone have a highscore that saves.
It's a 2D game/app, and people can get points/score by going up and collect a dot, this dot will destroy on impact and add a point to the score.
Also I'm using a scene for the game over screen, should I keep it like that or not?
Thanks in advance.
Answer by ray2yar · Jan 20, 2019 at 03:24 PM
I recommend checking out the tutorials on the unity website. They are excellent for beginners. You just need to shave down what you are wanting at its root.
So, for you, that's data persistence and saving. Basically you want to keep the high score and save it between play throughs. Check this video out:
https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
As for displaying that information, you want a UI canvas and a script that assigns values to it... So for example have a couple textboxes and Do something like this:
using UnityEngine;
using UnityEngine.UI;
public class Scores : MonoBehaviour {
public Text HighScoreText;
public Text MyScoreText;
public void DisplayScores()
{
HighScoreText.text = **retrieve highest score somehow
MyScoreText.text = **retrieve currect score somehow
}
}
Answer by highpockets · Jan 20, 2019 at 03:30 PM
It's not necessary to use a new scene for the game over GUI, but that really depends on what you want to accomplish. I would recommend doing some beginner tutorials on Coursera for example to get more familiar with things at this stage.
Anyhow, I'm assuming that you're displaying your score on a canvas during gameplay and when the game is over you have a few options because there are always several ways to skin a cat. You could just keep the canvas with the score on it that you have during gameplay and have a text object (with Game Over text) inside your canvas which is inactive until you set it to active via gameObject.SetActive(); and of course you could disable the other objects within the canvas to suit your Game Over look.
You could also just make a new game over canvas in the scene and have it inactive at start. This would require you to pass the int score to a child text object of this canvas in some way. In my opinion, the best way to do that would be in the start method. ex:
int score;
Start(){
//get score and store in store variable
score = GameObject.Find("GameScoreObjectName").GetComponent<ScoreScript>().scoreIntName;
}
Now you need to turn the int into a string and pass it to the text property of the Game Over Text object on the canvas. Good luck
Your answer
Follow this Question
Related Questions
Anyway To Set A Specific Part Of Code To A Scene? 2 Answers
My score system doesn't display or work? Please help me! 1 Answer
How do I add my Timer to my Score system in C# ? 0 Answers
Making a high score script 0 Answers
Highscore table C# HELP!!! 0 Answers