I’m doing the survival shooter and I would like to make a high score type of thing for my game. Would i make a GUI or a new scene. If you could just send me to a video that would be very helpful. Also if there would be a way to save the highscores and maybe to type a name or something in there. Please help and thanks in advance (I’m a beginner so try to leave it simple please.)
There is a Unity tutorial on counting and displaying a player’s score that you should start with:
This will give you the “basics” required to move forward with your project (I’m assuming from how you worded it your game is single-player?)
Here’s something to get you started
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public int score = 0;
public int highScore = 0;
string highScoreKey = "HighScore";
void Start(){
//Get the highScore from player prefs if it is there, 0 otherwise.
highScore = PlayerPrefs.GetInt(highScoreKey,0);
}
void Update(){
guiText.text = "Score:" + score.ToString();
}
void OnDisable(){
//If our scoree is greter than highscore, set new higscore and save.
if(score>highScore){
PlayerPrefs.SetInt(highScoreKey, score);
PlayerPrefs.Save();
}
}
}
Then the Leaderboard/Highscore script might be like this:
using UnityEngine;
using System.Collections;
public class LeaderBoard : MonoBehaviour {
public int highScore;
string highScoreKey = "HighScore";
void Start(){
highScore = PlayerPrefs.GetInt(highScoreKey,0);
//use this value in whatever shows the leaderboard.
}
}
The problem is your question is vague. There are multiple scenarios for a highscore. For example:
- You game is single player and players can only ever see their own highscore
- Your game is single player but there is a “shared” leaderboard/highscore of Top 10 Players etc
- Your game is multiplayer and has a shared leaderboard/highscore system
I’m sure if you YouTube “Unity Highscore Tutorial” you will probably find what you need.