My splash screen is level 0. I've got PlayerPrefs set up so that from my splash screen, if the PlayerPrefs "SavedLevel" is 1 or more, then the player goes straight to level 3 of the game. Otherwise they have to go through level 1 and level 2.
That part of the script worked fine.
On occasion, I want to re-set the PlayerPrefs "SavedLevel" to 0 by pressing the "enter" key whilst the splash screen is showing, and then make the player go through level 1 and level 2.
To do this, I added the function Update part at the bottom of the script, but it's not working. I still go straight to level 3.
Can someone please let me know what's wrong with the below script, and how I can change the PlayerPrefs from my splash screen?
Thanks.
var levelreached : int;
//Allows time for text to be read
yield new WaitForSeconds (20.00);
//Checks PlayerPrefs number
levelReached = PlayerPrefs.GetInt("SavedLevel");
//If playerPrefs is 1 or above, goes from splash screen to main menu
if (levelReached >= 1 ){
Application.LoadLevel(3);
}
else{
// moves to instruction level
Application.LoadLevel(1);
}
//Allows player to zero playerPrefs if they press "enter" during splash screen.
//Sets PlayerPrefs to zero
function Update () {
if (Input.GetKeyDown ("space")) {
PlayerPrefs.SetInt("SavedLevel",0);
Application.LoadLevel(1);
}
}