WorldItem - jimdroberts/FishMMO GitHub Wiki
Represents an item that exists in the world and can be interacted with or picked up by players.
-
[SerializeField] private BaseItemTemplate template
The item template for this world item, defining its type and properties. Set in the inspector or at runtime.
-
public uint Amount
The amount of items represented by this world item (e.g., stack size).
-
public BaseItemTemplate Template { get; }
Gets the item template for this world item, used to access item data and display info.
-
public override string Title { get; }
Gets the display title for the world item. Returns an empty string, meaning no title is shown in UI by default. Override this property in derived classes to provide a custom title.
- Attach the WorldItem component to a GameObject in your scene.
- Assign a BaseItemTemplate asset to the template field in the Inspector or at runtime.
- Set the Amount to represent the stack size or quantity.
- The item can be picked up or interacted with by players.
// Example 1: Setting up a WorldItem in the Unity Editor
// 1. Add the WorldItem script to a GameObject.
// 2. Assign a BaseItemTemplate asset to the template field.
// 3. Set the Amount as needed.
// Example 2: Accessing item data in code
var worldItem = GetComponent<WorldItem>();
Debug.Log(worldItem.Template.Name);
Debug.Log(worldItem.Amount);
- Always assign a valid BaseItemTemplate to ensure the world item is functional.
- Use the Amount field to represent stackable items or quantities.
- Override the Title property in derived classes to provide custom UI display if needed.
- Use WorldItem for all items that should exist in the world and be interactable by players.