var _bestTry = 0;
var _bestTime = 0;
function Awake() {
DontDestroyOnLoad(this);
}
function Update () {
if(_bestTry == 0) {
_bestTry = GameObject.Find("WinorEnd_Controller").GetComponent(script_winOrEnd).number_of_tries;
}
if(GameObject.Find("WinorEnd_Controller").GetComponent(script_winOrEnd).number_of_tries <= _bestTry) {
_bestTry = GameObject.Find("WinorEnd_Controller").GetComponent(script_winOrEnd).number_of_tries;
}
if(_bestTime == 0) {
_bestTime = GameObject.Find("WinorEnd_Controller").GetComponent(script_winOrEnd).current_time;
}
if(GameObject.Find("WinorEnd_Controller").GetComponent(script_winOrEnd).current_time <= _bestTime) {
_bestTime = GameObject.Find("WinorEnd_Controller").GetComponent(script_winOrEnd).current_time;
}
}
Hey guys, I have this bit of code. It is supposed to keep track of the best score in the scene. However I want this score to be kept when I’m restarting the level. At the moment, I am getting only the latest score. For example, if best try was 1 the first time, and 2 tries the second time, the high score will be 2 tries which is not correct.
I am restarting the level from a different script with Application.LoadLevel(sameLevel);
Thanks in advance!
playerPrefs is awesome! Ty!
– dai4