- Home /
HighScore Gui Text (Error) Please Help! :)
This is my script,I want that the "number" (variable Counter) saved in an earlier scene It script looks if it is over the highscore and if it is save it and remember it as a highscore in another scene, I dont know that bad: S this is the one I use for another scene:
var Counter : int;
function Start(){
Debug.Log(Counter);
Counter = PlayerPrefs.GetInt("Score");
guiText.text = "Score: "+Counter;
}
and it works for me but now another scene and saved as highscore failing me that not only saves the previous runs, and I want to save the highest and if is lowest do nothing. What could I do?
var Counter: int;
var highscore: int;
function Start (){
Counter = PlayerPrefs.GetInt("Score");
}
function Update (){
if(Counter>highscore);
{
highscore = Counter;
guiText.text = "Normal Map HighScore : " +highscore.ToString();
PlayerPrefs.SetInt("highscore",highscore);
}
}
Thanks, I wish it running!.
Already did it for you this time but please, next time format the code to make it readable (it's the fifth button from the left, the one that says Code Sample).
Answer by Andres-Fernandez · Oct 06, 2014 at 02:31 PM
Try using PlayerPrefs.Save after the SetInt.
I tried put a PlayerPrefes.Save();
but it isnt run, nothing was save, and the result that you get in the game is put in this picture, and i want that the best score, will put in this scene.
var Counter: int;
var highscore: int;
function Start (){
counter= PlayerPrefs.GetInt("Score");
}
function Update (){
if(Counter>highscore);
{
highscore = Counter;
guiText.text = "Normal $$anonymous$$ap HighScore : " +highscore.ToString();
PlayerPrefs.SetInt("highscore",highscore);
PlayerPrefs.Save();
}
}
This dont run.. :/
var Counter: int;
var highscore: int;
function Start (){
counter= PlayerPrefs.GetInt("Score");
}
function Update (){
if(Counter>highscore);
{
highscore = Counter;
guiText.text = "Normal $$anonymous$$ap HighScore : " +highscore.ToString();
PlayerPrefs.SetInt("highscore",highscore);
PlayerPrefs.Save();
}
}
I tried it, the other day and it doesnt run :/
The problem is that you are saving "highscore" but inside Start function you are trying to get "Score". Both the saved and the loaded value must have the same name. Line 6 should be:
highscore = PlayerPrefs.GetInt("highscore");
But, var counter, the number that it give me is the number that i need in the other scene , and i need this number to check if is lower or higher than the HighScore, if i put this CODE
var Counter: int;
var highscore: int;
function Start (){
highscore = PlayerPrefs.GetInt("highscore");
}
function Update (){
if(Counter>highscore);
{
highscore = Counter;
guiText.text = "Normal $$anonymous$$ap HighScore : " +highscore.ToString();
PlayerPrefs.SetInt("highscore",highscore);
PlayerPrefs.Save();
}
}
when the scene change, the counter put 0, and i have other counter in the other scene...
Umm! Yes but how i can save the Counter variable to the PlayerPrefs? And put correct the line 6? I dont know certanly the best form
Answer by Andres-Fernandez · Oct 06, 2014 at 03:06 PM
Ok, I understood it wrong. So you just need to save your Counter variable to the PlayerPrefs too (and replace back line 6, as what I suggested is wrong).
Answer by cboxgo · Oct 09, 2014 at 07:34 AM
Are you sure that you saved the 'counter' in the previous scene?