- Home /
High Score on Mobile
Hello everyone , im making a mobile game and i have score but there is no highscore im not making online leaderboard thing , it's my normal score code ;
void StoreHighscore(int newHighscore)
{
int oldHighscore = PlayerPrefs.GetInt("highscore", 0);
if(newHighscore > oldHighscore)
PlayerPrefs.SetInt("highscore", newHighscore);
}
and this code attached to the Game over screen ;
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public GUIStyle style;
void OnGUI()
{
GUI.Label (new Rect (50, 50, 1000, 500), "Score : " + PlayerPrefs.GetInt("SaveScore") , style );
//display saved score
}
}
Any idea how to make high score ?
i think reason is because its in different scripts try putting em together
void Update()
{
score = newHighscore;// set your score to your new highscore
}
Jeric , when i do your code it's always same with score.
private int score = 0;
private int highscore = 0;
void Update() {
fuel -= 1 * Time.deltaTime;
if (fuel > 35 ) {
fuel = 35;
}
if (fuel < -2)
{
Application.LoadLevel("gameOver");
PlayerPrefs.SetInt("SaveScore",score);
// save your current score
PlayerPrefs.SetInt("SaveHighScore",highscore);
}
if ( score > highscore ) {
score = highscore;// set your score to your new highscore
}
Fixed it :)
if (fuel < -2)
{
Application.LoadLevel("gameOver");
PlayerPrefs.SetInt("SaveScore",score);
// save your current score
}
if ( score > highscore ) {
highscore = score; // set your score to your new highscore
PlayerPrefs.SetInt("SaveHighScore",highscore);
Answer by AortaStudios · Sep 17, 2014 at 09:55 AM
Hello,
We have developed a very easy to use asset on the store that allows easy handling of scores and high-scores across multiple devices including mobile, allowing local and online storage. It is a case of dragging in a prefab and attaching a new component allowing access to the helper functions.
The asset can be found here: https://www.assetstore.unity3d.com/en/#!/content/20581
Best of luck, Aorta
Your answer
Follow this Question
Related Questions
I'm trying to set a high score but I can't display it in another scene? 2 Answers
Playerprefs not work!? 0 Answers
Saving highscore problem 1 Answer
PlayerPref set int and get int 1 Answer
PlayerPrefs Highscore problem 1 Answer