Menu
CoddyTech

Recap: Item Database

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 28 of 64.

challenge icon

Challenge

Medium

Give the blacksmith's shop a shared item database.

  1. ItemData: a ScriptableObject with [CreateAssetMenu], public string itemName and int price. ItemDatabase: the same, with public List<ItemData> items;.
  2. In Shop, add public ItemDatabase database;. itemText shows Iron Sword: 30 gold, goldText shows Gold: 50.
  3. Right selects the next item, Left the one before, wrapping at both ends.

Press Play and browse. Then Check.

Try it yourself

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;

public class Shop : MonoBehaviour
{
    public TMP_Text itemText;
    public TMP_Text goldText;
    public int gold = 50;

    // The database field and browsing with the arrows go here
}

All lessons in Game Architecture in Unity

Practice on your own: Unity playground