Merchant
This document explains how to set up a Merchant in the Inventory System, including how to configure the necessary components and UI connections.
1. Create Merchant GameObject
Create an empty GameObject (e.g., MerchantNPC).
Add the following components:
Merchant (Script) — Controls trading, crafting, and dismantling logic. 🔔 Note: When you add the Merchant script, Unity automatically adds an Inventory component because Inventory is a [RequiredComponent] for Merchant to work.
Inventory (Script) — Stores the merchant's items.
Merchant Hotspot (Script) — Manages player interaction with the merchant and opens the shop UI.
Savable Object (Script) — (Optional) Enables saving and loading the merchant's inventory and state.
Box Collider — Used to detect interaction zones for the merchant.
Optional: Add a character model and animations (such as Idle animations) as a child of the Merchant GameObject for better visuals.
2. Setup Components
Merchant (Script)
Core script for managing trading, crafting, and dismantling.
Settings:
Can Trade: Enable buying/selling.
Can Craft: Enable crafting.
Can Dismantle: Enable dismantling.
Sell Price Modifier controls how much money the player receives when selling an item to the merchant.
It is a multiplier applied to the base item price.
For example, if the Sell Price Modifier is set to 0.5, the player will only receive 50% of the item's original value when selling.
Example:
Item Base Price = 100 Gold
Sell Price Modifier = 0.5
Player sells the item ➔ Receives 50 Gold.
Inventory (Script)
The Inventory component attached to the Merchant defines the list of items available for trading, crafting, or dismantling. It acts as the merchant's personal storage and controls what they offer to the player.
Default Items This is the list of items that the merchant starts with. Each entry includes an item reference and the quantity the merchant has in stock.
Store Categories Separately This option is used if you want to organize merchant items into different categories (like weapons, armor, potions, etc.).
Default Category Slots Only relevant if categories are stored separately. Defines how many slots each category will have.
Weight Capacity Specifies the maximum weight the merchant's inventory can carry. In most merchant cases, this is set high enough to avoid hitting limits.
Over Weight Allowed If enabled, the merchant can exceed the weight capacity.
Has Fixed Number Of Slots allows either flexible or restricted inventory sizes depending on the game design.
Default Number Of Slots Sets the starting number of available inventory slots.
How It Works for the Merchant
The Inventory defines exactly what items the merchant can sell, craft, or dismantle.
When the player opens the merchant shop, the available items are pulled directly from this inventory.
You can prefill this list with basic starting stock or dynamically modify it during runtime if needed.
Merchant Hotspot (Script)
Handles player interaction.
Settings:
Interact UI Prefab: Assign the popup UI.
Shop Opener: Assign the shop/trading UI.
The Shop Opener field in the Merchant Hotspot must be linked to the Shop UI.
Locate the UI under your player setup:
📝 This UI is created when you set up the player's Inventory system initially.
Quick Summary
Always add both Merchant and Inventory components to the Merchant GameObject.
Link the Shop/Crafting/Dismantle UI to the Shop Opener field in the Merchant Hotspot.
(Optional) Add a character model and animations to improve the merchant's appearance.
Last updated