Пример #1
0
    void Start()
    {
        InitializeSaveData();

        _gamplayHud = FindObjectOfType <GamplayHUD>();
        _gamplayHud.UpdateHighScoreUI(highScore);
        _gamplayHud.UpdateCoinText(coinsPickedUp);

        StartCoroutine(AddToScoreEverySecond());
    }
Пример #2
0
    //When the confirm purchase button is clicked
    void OnBuyButtonClick(ShopItem shopItem, GameObject item)
    {
        shopItem.isOwned = true;

        //Show purchased item
        GameObject ownedItem = Instantiate(ownedItemPrefab, itemsOwnedContainer);

        ownedItem.transform.GetChild(0).GetComponent <Image>().sprite = shopItem.itemSprite;

        //The button can no longer be interacted with, making UI reflect this
        item.GetComponent <Button>().interactable = false;
        item.transform.GetChild(0).GetComponent <Image>().color = Color.gray;
        item.transform.GetChild(1).GetComponent <Image>().color = Color.gray;
        item.transform.GetChild(2).GetComponent <Text>().text   = "Owned";

        //Subtract coins and update coin text
        PlayerPrefs.SetInt("coinsPickedUp", PlayerPrefs.GetInt("coinsPickedUp") - shopItem.itemPrice);
        _gamplayHud = FindObjectOfType <GamplayHUD>();
        _gamplayHud.UpdateCoinText(PlayerPrefs.GetInt("coinsPickedUp"));

        Debug.Log("Purchased " + shopItem.name);
    }
Пример #3
0
 //When a coin is collected
 public void AddToCoinsPickedUp(int coinsAdded)
 {
     coinsPickedUp += coinsAdded;
     _gamplayHud.UpdateCoinText(coinsPickedUp);
 }