Hi all,
I am having a problem with a script, atm I have a script that declare certain playerdatas (lives, score etc…):
public static int Lives;
public static int firstRun;
etc...
Now, the reason why I am storing this “firstRun” is that I have a menu with all the levels, in the form of buttons.
It works in a way that, if I reached level 1 at best, I can’t go to menu and select level 2, if I reached max level 3, I can’t go to menu and select level 4, etc…but the problem is, I set the playerprefs everytime I move from a scene to another, and it happens that, for example, you reached level 4, go to menu, you go back to level 1, from level 1 you reach level 2, and it save level 2 as your “max”.
So I thought I could make a script that check if it’s the first time you reach certain scene (atm you move from a scene to another with a trigger collider on a door). The script is supposed to, if it’s your first time reaching a certain level, to set playerprefs to the new level you reach, but if you already went into that level, it simply load the new level and doesn’t save anything (and so it keeps you last saving, which is the highest level you ever reached).
Here is the “corrupted” script :
public void Start()
{
PlayerData.firstRun = PlayerPrefs.GetInt("firstRun");
}
void OnCollisionEnter2D(Collision2D coll)
if (coll.collider.gameObject.tag == "tutorial_platform1")
if (PlayerData.firstRun == 0)
{
PlayerPrefs.SetInt("levelReached", 2); //storing index
SceneManager.LoadScene("tutorial_2");
PlayerPrefs.SetInt("firstRun", 2); //I set it to 2 but any number different from 0 is fine, as long as is it is different from 0.
}
else
{
SceneManager.LoadScene("tutorial_2");
}
Any help would be greatly appreciated.
Thanks in advance