Script
Script
Serializable]
}
using UnityEngine;
using UnityEngine.UI;
using TMPro;
skins[selectedCharacter].SetActive(true);
foreach(Character c in characters)
{
if (c.price == 0)
c.isUnlocked = true;
else
{
//if condition is true the false with apply on the condition in
other case true will apply if coindition is not equal
c.isUnlocked = PlayerPrefs.GetInt(c.name, 0) == 0 ? false : true;
}
UpdateUI();
}
public void ChangeNext()
{
skins[selectedCharacter].SetActive(false);
selectedCharacter++;
if (selectedCharacter == skins.Length)
selectedCharacter = 0;
skins[selectedCharacter].SetActive(true);
if(characters[selectedCharacter].isUnlocked)
PlayerPrefs.SetInt("SelectedCharacter", selectedCharacter);
UpdateUI();
}
skins[selectedCharacter].SetActive(true);
if (characters[selectedCharacter].isUnlocked)
PlayerPrefs.SetInt("SelectedCharacter", selectedCharacter);
UpdateUI();
}
public void UpdateUI()
{
coinsText.text = "Coins: " + PlayerPrefs.GetInt("NumberOfCoins", 0);
diamondText.text="Dimd: "+PlayerPrefs.GetInt("DiamondsOfCoins",0);
if (characters[selectedCharacter].isUnlocked == true)
{
unlockButton.gameObject.SetActive(false);
unlokButtonn.gameObject.SetActive(false);
}
else
{
unlockButton.GetComponentInChildren<TextMeshProUGUI>().text = "Price:
" + characters[selectedCharacter].price;
if (PlayerPrefs.GetInt("NumberOfCoins", 0) <
characters[selectedCharacter].price)
{
unlockButton.gameObject.SetActive(true);
unlockButton.interactable = false;
}
else
{
unlockButton.gameObject.SetActive(true);
unlockButton.interactable = true;
}
unlokButtonn.GetComponentInChildren<TextMeshProUGUI>().text= "Dimd:
"+characters[selectedCharacter].dimd;
if(PlayerPrefs.GetInt("DiamondsOfCoins",0)<characters[selectedCharact
er].dimd)
{
unlokButtonn.gameObject.SetActive(true);
unlokButtonn.interactable=false;
}
else
{
unlockButton.gameObject.SetActive(true);
unlokButtonn.interactable=true;
}
int diamond=PlayerPrefs.GetInt("DiamondsOfCoins",0);
int dimd = characters[selectedCharacter].dimd;
PlayerPrefs.SetInt("DiamondsOfCoins",diamond - dimd);
PlayerPrefs.SetInt(characters[selectedCharacter].name, 1);
PlayerPrefs.SetInt("SelectedCharacter", selectedCharacter);
characters[selectedCharacter].isUnlocked = true;
UpdateUI();
}