Menu
CoddyTech

Recap: Upgrade Shop

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

This chapter wired buttons to code, kept the screen in step with the numbers, and turned buttons on and off. The shop puts them together.

challenge icon

Challenge

Easy

Build the mine's shop.

  1. In Start(), hook the buttons: Mine adds perClick to coins; the pick (pickCost) adds 1 to perClick and costs 10 more; the lantern (lanternCost) adds 3.
  2. Write Refresh(), called in Start() and after each click: Coins: 12, Pick: 20, Lantern: 25 or Lantern: owned. Only affordable, unowned upgrades are interactable.

Press Play and 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;
    private int coins;
    private int perClick = 1;
    private bool hasLantern;

    // Hook the three buttons in Start(), and show everything in Refresh()
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Building Real Games

Practice on your own: Unity playground