0
Unity - C#: cannot save Buttons into PlayerPrefab
Hello, If somebody can help, I don't have idea anymore. I have several levels (buttons that open room to play game) and this buttons are currently "locked" with antoher button in front of others. When i click "locked button" first show me the popUp and then with another button in a popUp i can unlocked selected level. Everythings is working perfectly but when i change the Scene or turn off the game, the unlocked buttons are still locked. Problem is because when you unlock the level you spent xy Coins. Can somebody help me how can i save that the button when is unlocked stay unlocked? Thanks!
1 Resposta
0
My Code:
int[] levels = new int[2];
public List<GameObject> LevelButtons;
int i = 0;
public GameObject popupPremaloCoinsov;
public void UnlockLevel()
{
int odkleneniLeveli = PlayerPrefs.GetInt("Levels", levels[i]);
if (i == 0)
{
LevelButtons[i].SetActive(false);
}
LevelButtons[i++].SetActive(false);
CoinCollecting.coinsAmount = -50;
CoinCollecting.UpdateCoins();
PlayerPrefs.SetInt("Levels", i);
PlayerPrefs.Save();
}
public void TakeCoins()
{
if (PlayerPrefs.GetInt("Coins", CoinCollecting.coinsAmount) >= 50 )
{
UnlockLevel();
}
else
{
popupPremaloCoinsov.SetActive(true);
}
}