Menu
CoddyTech

Recap: Coins in the Bank

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

challenge icon

Challenge

Medium

A treasure hunt. Space digs up a coin into the pocket, and the Bank button moves the pocket into the bank. Only the bank is saved: coins still in the pocket are lost when the game is closed. Write Digger:

  • Space adds 1 coin to pocket.
  • Clicking Bank adds the pocket to bank, empties the pocket and saves the bank under the key Bank.
  • A new player's bank starts with 10 coins, a welcome gift. A bank that was saved, even at 0, loads as it was saved.
  • The texts always show the current values, as Pocket: 3 and Bank: 12.

Press Play, dig, bank, and play again, then Check.

Try it yourself

using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class Digger : MonoBehaviour
{
    public TMP_Text pocketText;
    public TMP_Text bankText;
    public Button bankButton;

    private int pocket;
    private int bank;

    void Start()
    {
    }

    void Update()
    {
    }
}

All lessons in Building Real Games