I am setting up a local high score for a game in unity 3d where, for every second that passes, you gain +1 point.
Right now I have this script set up on an empty game object so I can display the points in real time, but when you die and the game goes back to the menu scene how do I then load your previous score and your highest score, into the menu scene? I have looked many places and cant find a valid option that helps me, also pretty new to unity but I have a mild understanding of js, will also take C# but more comfortable with js. Do I need an object set up in the menu pulling data from MainGame scene? Been struggling on this one for a while.
var textfield : GUIText;
static var score : int;
function Start()
{
score = 0;
}
function Update()
{
score = Time.timeSinceLevelLoad;
UpdateScoreText();
}
function UpdateScoreText()
{
textfield.text = score.ToString();
}
The most obvious way for this and the easiest is using the playerprefs. u can just save the value and then load from anywhere you like even if you close the game and reopen it.
ex: Saving)
PlayerPrefs.SetString("the string Title", "the text you want to save");
Loading)
print (PlayerPrefs.GetString("the string Title"));