Item Drop
Scripting with the ItemDrop class.
An ItemDrop
is a GameObject
that represents a dropped Item Stack.
Fields & Properties
id
The item drop ID. This can be used to determine if the item drop has already been obtained.
string
public
itemStack
The item stack that this object represents.
ItemStack
public
useTimeout
If the item drop should be despawned after some time. Despawn is scheduled on start.
bool
public
spriteRenderer
The sprite renderer component that displays the item sprite.
SpriteRenderer
private
Creating an Item Drop
To create an ItemDrop
, use the SpawnInstance
method. You will need a reference to an ItemStack
. This method spawns an instance of an ItemDrop
in the game world. You can set the position and whether timeout should be enabled.
Handling Auto Disable
Item drops can auto-disable themselves on start with the logic of your choice by setting the ItemDrop.shouldEnable
field.
Timeout
If timeout was enabled when spawning an item drop instance, the item drop will be automatically destroyed based on the itemDropTimeout
field in Settings.
Pick Up
Picking up item drops is handled by the inventory. Once an item drop is picked up, the ItemStack
it represents is added to the inventory and the ItemDrop
instance is destroyed.
Checking All Drops In Range
You can get the full list of items that the player is in range of with the dropsInPickupRange
field.
Last updated