Crafter
Scripting with the Crafter class.
The Crafter
class is used to craft an item. This class can craft any item as long as the correct item combinations are provided.
Fields & Properties
combineItems
A list of items to use for crafting. A single stack of each item will be used.
List<ItemStack>
public
Creating a Crafter
Adding Items
To add items, use the TryAddItem
method. This method will return true if an ItemStack
was successfully added. It will only add a single stack on an ItemStack
. It may fail if the ItemStack
is already added.
Removing Items
You can use the RemoveItem
method to remove an item.
It's also possible to remove an item at a specific index.
Crafting
To craft, use the TryCraft
method. The Crafter
looks at all Craft
scriptable objects to find one that matches the specific ItemStack
combination (the combineItems
field is the combination). If one matches, the resultItem
of that Craft
will be crafted (added to the inventory) and true
will be returned. Otherwise, false will be returned and no item will be crafted.
TryCraft
accepts a bool parameter that enables or disables the crafting cost. Crafting may fail if the player does not have sufficient currency.
You can use CanCraft
to check if something can be crafted. This method accepts 2 bool
parameters: if the cost should be considered and if the failure reason should be invoked.
Last updated