Merchant - jimdroberts/FishMMO GitHub Wiki
Represents a merchant NPC that players can interact with to buy or sell items. Inherits from Interactable and uses a MerchantTemplate for configuration.
-
public MerchantTemplate Template
The template containing merchant configuration, such as inventory and description.
-
private string title
The display title for this merchant, shown in the UI. Defaults to "Merchant" but can be set from the template.
-
public override string Title { get; }
Gets the display title for this merchant, used in UI elements.
-
public override void OnAwake()
Called when the merchant is awakened in the scene. Sets the title from the template description if available.
-
public override bool CanInteract(IPlayerCharacter character)
Determines if the specified player character can interact with this merchant. Requires a valid template and that the base interaction checks pass. character (IPlayerCharacter): The player character attempting to interact. Returns: True if interaction is allowed, false otherwise.
- Attach the Merchant component to an NPC GameObject in your scene.
- Assign a MerchantTemplate asset to the Template field in the Inspector.
- The merchant will display the title from the template's description in the UI.
- Players can interact with the merchant to buy or sell items if the template is assigned.
// Example 1: Setting up a Merchant NPC in the Unity Editor
// 1. Add the Merchant script to an NPC GameObject.
// 2. Assign a MerchantTemplate asset to the Template field.
// 3. The merchant will now use the template's description as its title.
// Example 2: Accessing the title in code
var merchant = GetComponent<Merchant>();
Debug.Log(merchant.Title);
- Always assign a MerchantTemplate to ensure the merchant is functional and displays the correct title.
- Use the template to configure inventory, abilities, and other merchant properties.
- Override OnAwake for additional initialization logic if needed.
- Use CanInteract to enforce custom interaction rules for merchants.