Menu
CoddyTech

Recap: Upgrade Shop

Part of the Building Real Games section of Coddy's Unity journey. Lesson 11 of 56.

challenge icon

Challenge

Easy

A gold mine you dig by clicking. Write GoldMine.cs (the scene links the three buttons and the three texts):

  • Each click on Mine earns coins, 1 per click at first. coinsText shows them, as Coins: 12.
  • The pick costs pickCost (10). Buying it spends the coins, adds 1 to the coins per click and raises its price by 10. Its button's text, pickText, shows the price, as Pick: 20.
  • The lantern costs lanternCost (25) and can be bought once: it adds 3 to the coins per click, and from then on lanternText reads Lantern: owned. Before that it reads Lantern: 25.
  • An upgrade's button is interactable only while you have enough coins for it, and the lantern's never again once it is owned.
  • All three texts and both buttons are right from the start.

Press Play, dig, buy both upgrades, then Check.

Try it yourself

using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class GoldMine : MonoBehaviour
{
    public Button mineButton;
    public Button pickButton;
    public Button lanternButton;
    public TMP_Text coinsText;
    public TMP_Text pickText;
    public TMP_Text lanternText;
    public int pickCost = 10;
    public int lanternCost = 25;

    // Mine earns coins; the pick and the lantern are upgrades, usable only when you can afford them
}

All lessons in Building Real Games