Platformer PRO provides support for many kind of collectible items, armour, weapons, power-ups, etc. Before you can create and use items you must setup your ItemTypeManager.
Once you have an ItemTypeManager, then to get started with Items:
- Add an ItemManager to your Character GameObject (see ItemManager below).
- Make sure your character has a correctly set up HurtBox or other CharacterReference.
- Add a GameObject to represent your item. Make sure this is in a non-geometry layer that can interact with Characters (e.g. the 'Collectible_Projectile' layer that is setup by default).
- Add the Item component to your Item GameObject.
- Add a 2D collider to your Item GameObject.
- Create a GameObject that is a child of your Item GameObject
- Add a visible component (such as a SpriteRenderer) to this child GameObject.
Note: Its not vital that the visible component be a child but this is good practice as it allows you to effect the visible component of the item without affecting its behaviour.
There are four types of items:
|STACKABLE||An item that can be stacked up in the inventory until some maximum is reached. For example coins or stars.|
|SINGLE||An item of which the player can only have one.|
|KEY||Special item type used to unlock doors. See Doors for more information.|
|POWER_UP||Special item type which grants the user new powers. See Power Ups.|
The item type is a string identifier for the type of item. It will be chosen from the list of items defined in your ItemTypeManager.
Create a Stack of Items
If you wish to add more items to a stack (e.g. 10 bullets instead of 1), update the Item component to instead be a StackableItem. And enter an amount in the Amount field.
The ItemManager component handles collecting and using items. It must be added to your Character GameObject or to a child of your Character GameObject.
Configuring Stacks of Items
The ItemManager allows you to configure stackable items by adding one or more items with the following details:
|Type||Unique ID for the item type (e.g 'fuel' or 'COIN').|
|Max||Maximum number of items allowed (i.e. how many can the Character hold).|
|Starting Count||Allow your character to start with some of this item. For example you may want to start with 20 bullets or 100 fuel.|
The ItemManager is a Persistable (see Persistables) and thus allows you to persist the state of the items between levels, games or even play sessions. See PlatformerProGameManager.