- Home /
Loading a score on a scene
Hi there,
Im making a race game with a timer(GUI TEXT). When I reach the final line, the timer stops. I would simply wish to put that score ( the time, in fact ) on a new scene. Like this I could always see the best score every time I finish the race and update that score ( the time ) if I make a best race.
I know that can look easy for some of you but not for me.
Answer by flamy · Jul 14, 2012 at 07:10 PM
In the end of race in first scene save the score variable to a playerprefs using the function SetInt(assuming ur score is int). and in the next scene you can fetch the socre using GetInt function. Sample code,
// in the race screen
PlayerPrefs.SetInt("CurrentScore",scoreVariable);
//In the result screen
guiText.text=""+PlayerPrefs.GetInt("CurrentScore");
Answer by Toy · Jul 14, 2012 at 07:30 PM
Thank you im going to try this. But waht is the string supposed to be, I see you have used "CurrentScore", for me it goes like this : PlayerPrefs.SetFloat("",timer);
Im not sure what to write, my GUI text ???
thanks
the string is nothing but a key to access the value back.. like a variable name... u could have seen that im using the same CurrentScore in getInt too..