Recap: Item Database
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 28 of 64.
Challenge
MediumGive the blacksmith's shop a shared item database.
ItemData: a ScriptableObject with[CreateAssetMenu], publicstring itemNameandint price.ItemDatabase: the same, withpublic List<ItemData> items;.- In
Shop, addpublic ItemDatabase database;.itemTextshowsIron Sword: 30 gold,goldTextshowsGold: 50. - 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
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular TurretRecap: Twin Cannon4Serialized Data
Serializable ClassesLists in the InspectorEnums in the InspectorRecap: Loot TableRecap: Roll the Loot2Interfaces in Unity
IDamageableInterfaces and TryGetComponentGetComponentsRecap: Interact KeyRecap: Nearest in Reach5ScriptableObjects
Data AssetsWeapon StatsShared SettingsSave the WindWaves as DataRecap: Item DatabaseRecap: Buy from the ShopPractice on your own: Unity playground