How to Set High Score On Unity + C# Free Script
So, In this article we gonna to see how to set high score on game deveoping engine unity with C# script.Unity is an all purpose game engine that supports 2D and 3D graphics, drag and drop functionality and scripting through C#. Two other programming languages were supported: Boo, which was deprecated with the release of Unity 5 and UnityScript.
Highscore is the main part of the game, so in this tutorial we gonna to see how to set and reterive highscore with diffent scenes and differne scripts with very easiest method.
Advertisements
by using this methos you can store not only highscore also we can store string,float,int variable values permanently
there is no variable decalration or values assignment required,
so lets gets started. first we need a game scene to set high score.
void update()
{
if(currentscore > PlayerPrefs.GetInt("highscore");
PlayerPrefs.SetInt("highscore", currentscore);
}
From this code, i am checking current score by highscore, if current score is greater than high score then set new score as a high score..
Main Details
To Assing High Score
PlayerPrefs.SetInt("highscore", currentscore);
highscore is an string like a varibale to store high score.
current score is an int variable
To Get High Score
int a = PlayerPrefs.GetInt("highscore");
here A stores high scores from variable highscore.
Advertisements
we can use this methods for store string,int,float datatype values, also we can use/get values from any script we want..
To Download this project Click download below.
So, In this article we gonna to see how to set high score on game deveoping engine unity with C# script.Unity is an all purpose game engine that supports 2D and 3D graphics, drag and drop functionality and scripting through C#. Two other programming languages were supported: Boo, which was deprecated with the release of Unity 5 and UnityScript.
Highscore is the main part of the game, so in this tutorial we gonna to see how to set and reterive highscore with diffent scenes and differne scripts with very easiest method.
Advertisements
by using this methos you can store not only highscore also we can store string,float,int variable values permanently
there is no variable decalration or values assignment required,
so lets gets started. first we need a game scene to set high score.
Here, the high score is now 0, to set a highscore just follow given line,
PlayerPrefs.SetInt("highscore", score);
highscore is an public variable so we don't need to decalare any variable.. you can create anything you want.
exmable to set highscore
In UPDATE Function
{
if(currentscore > PlayerPrefs.GetInt("highscore");
PlayerPrefs.SetInt("highscore", currentscore);
}
From this code, i am checking current score by highscore, if current score is greater than high score then set new score as a high score..
Main Details
To Assing High Score
PlayerPrefs.SetInt("highscore", currentscore);
highscore is an string like a varibale to store high score.
current score is an int variable
To Get High Score
int a = PlayerPrefs.GetInt("highscore");
Advertisements
we can use this methods for store string,int,float datatype values, also we can use/get values from any script we want..
To Download this project Click download below.
3d codes download highscore project free projects how to set get high score unity lines program series tutorial set high score unity unity unity 2d unity engine unity high score tutorial