I have simple coin system. I have prefab named “PlayerBank” and have 3 levels which based on coins. I want to do like something like this. How can i do that?
if (PlayerPrefs.HasKey("PlayerBank"))
{
//if lower than int user cant click level
}
else
{
//if higher than int user can click level
}
Do you have a scene for each level? In this case you have to use SceneManagement to load the level.
The code below is not perfect. It’s just an example of how you could do it!
using UnityEngine.SceneManagement
...
/* if you are using GameObjects
public GameObject level1;
public GameObject level2;
public GameObject level3;
*/
void Example()
{
int nameWhateverYouWant;
if (PlayerPrefs.HasKey("PlayerBank"))
{
nameWhateverYouWant = PlayerPrefs.GetInt("PlayerBank", 0);
if (nameWhateverYouWant == 1)
{
SceneManagement.LoadScene("Level1");
//level1.SetActive(true);
}
else if (nameWhateverYouWant == 2)
{
SceneManagement.LoadScene("Level2");
//level2.SetActive(true);
}
else
{
SceneManagement.LoadScene("Level3");
//level3.SetActive(true);
}
}
}