0% found this document useful (0 votes)
30 views

Script

The document defines a Character class with properties like name, price, and whether it is unlocked. It also defines a CharacterSelect class that manages character selection and unlocking. It handles selecting characters, updating the UI to show coin/gem counts and unlock button states, and unlocking characters by deducting coins/gems when the button is clicked.

Uploaded by

Me. Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Script

The document defines a Character class with properties like name, price, and whether it is unlocked. It also defines a CharacterSelect class that manages character selection and unlocking. It handles selecting characters, updating the UI to show coin/gem counts and unlock button states, and unlocking characters by deducting coins/gems when the button is clicked.

Uploaded by

Me. Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

[System.

Serializable]

public class Character


{
public string name;
public int dimd;
public int price;

public bool isUnlocked;

}
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class CharacterSelect : MonoBehaviour


{
public GameObject[] skins;

public int selectedCharacter;


public Character[] characters;

public Button unlockButton;


public Button unlokButtonn;
public TextMeshProUGUI coinsText;
public TextMeshProUGUI diamondText;

private void Awake()


{
selectedCharacter = PlayerPrefs.GetInt("SelectedCharacter", 0);
foreach (GameObject player in skins)
player.SetActive(false);

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();
}

public void ChangePrevious()


{
skins[selectedCharacter].SetActive(false);
selectedCharacter--;
if (selectedCharacter == -1)
selectedCharacter = skins.Length - 1;

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;
}

public void Unlock()


{
int coins = PlayerPrefs.GetInt("NumberOfCoins", 0);
int price = characters[selectedCharacter].price;
PlayerPrefs.SetInt("NumberOfCoins", coins - price);

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();
}

You might also like