Game Development Reference
In-Depth Information
Implementing the ObjectInteraction script
The ObjectInteraction class defines how the interactive object will be manip-
ulated when an interaction occurs between the object and the player. Perform the
following steps to implement this:
1. Two enumerations are required to specify the action and the type of action.
The action will be what we do with the item (put in inventory and use) initially,
as shown in the following code:
public enum InteractionAction
{
Invalid = -1,
PutInInventory = 0,
Use = 1,
}
2. The corresponding type specializes this behavior by determining if the object
is unique or can be accumulated with other interactive objects of the similar
type. A unique interaction specifies that ObjectIneraction will insert this
interactive object in a unique slot in InventoryMgr , while an accumulate
interaction specifies that ObjectInteraction will insert this item (and in-
crease the quantity) in the first available slot that matches the type set in
CustomGameObj , as shown in the following code:
public enum InteractionType
{
Invalid = -1,
Unique = 0,
Accumulate = 1,
}
3. We keep the following two public variables to store the two enumerations dis-
cussed in the previous step:
public InteractionAction interaction;
public InteractionType interactionType;
Search WWH ::




Custom Search