Loot Box
Scripting with the LootBox class.
A class which can be used to receive a randomized selection of items.
Fields & Properties
id
An ID that can be used to determine if a loot box has already been obtained.
string
public
possibleDrops
A list of all possible item drops.
List<LootBoxDrop>
public
minItemDrop
The minimum amount of items that can be dropped from this loot box.
int
public
maxItemDrop
The max amount of items that can be dropped from this loot box.
int
public
Creating a Loot Box
Since loot boxes are scriptable objects, you can create them with ScriptableObject.CreateInstance
.
Working with a Loot Box
Setting Possible Drops
Creating a Drop List
The code below is an example of how you can create a drop list. In the example, 2 possible drops are added to a loot box, each with a 50% probability of dropping. The myItem
and myOtherItem
fields are instances of an Item.
Randomized Drop Amount
A random number of items are dropped based on the minItemDrop
and maxItemDrop
fields.
Getting Drop Chances
You can get the drop chance of each possible drop as a percentage out of 100 by it's index with the CalculateDropChance
method.
Getting Loot
The GetLoot
method can be used to get random loot. This can be considered as opening the loot box. This returns an ItemStack
list.
Last updated