Special Backpack - this component was created for example game, but we think it can be useful for you. With this component you can stack up to several kinds of elements, and set it in a position you want. When game starts backpack spawns elements to spawn points, which you need create manually. By doing that you can create backpacks like this:
Resources - a list of resource element's settings.
Type - resource element's type
Prefab - element's prefab which will be spawned.
Spawn Point - a list of transforms which will be used at spawning elements.
Auto Spawn - turns on spawn at game start.
Resource Type - enum which contains your backpack resource types. You can change it and name how you want.
public enum ResourceType
{
Apple,
Orange,
}
QUESTIONS:
How to use it?
At first rename the ResourceType types and create a custom prefab for every type.
Add a special backpack component to your backpack game object and set Resources up.
After it create a custom spawn point transforms and add to Spawn Points list.
If you want to call SpawnItems() method manually set Auto Spawn false.
2. How to spawn items manually?
[SerializeField] private SpecialBackpack _specialBackpack;
private void Start()
{
_specialBackpack.SpawnItems();
}
3. How to change items count?
[SerializeField] private SpecialBackpack _specialBackpack;
private void Start()
{
//You can add items only of the type already in the backpack
//If you want to add others, you must first empty the backpack
_specialBackpack.AddItems(10, SpecialBackpack.ResourceType.Apple);
_specialBackpack.RemoveItems(10);
//If you need to know backpack is full or not, you can use it
if (_specialBackpack.IsBackpackFull())
{
}
}