Backpack - is a component that allows you to stack any items into the number of columns you need.
Prefab - object which you want to stack.
Items Offset - offset between items in column.
Columns List - a list of transforms of the starting spawn point for each column.
Max Items Per Column - maximum number of objects per column.
Default Items Count - number of objects that will be shown at start.
ADVICE: We advise you to add the script backpack to the player, so you will be more comfortable in the future to contact the backpack and add or decrease items.
QUESTIONS:
1. How to change items count? - Get the link to the backpack and change the ItemsCount value in any way convenient to you.
[SerializeField] private Backpack _backpack;
private void Start()
{
_backpack.ItemsCount = 10;
_backpack.ItemsCount += 10;
_backpack.ItemsCount -= 10;
}
If your script and your backpack script are hanging on the same game object, you can do so.
private void Start()
{
var backpack = GetComponent<Backpack>();
backpack.ItemsCount++;
backpack.ItemsCount--;
}
2. How to get maximum items count? - Backpack.MaxItemsCount keeps this value.
[SerializeField] private Backpack _backpack;
private void Start()
{
if (_backpack.ItemsCount == _backpack.MaxItemsCount)
{
Debug.Log("Backpack is full.");
}
}