Opticgamer
Member
Hello, I saw another thread where someone provided an simple inventory solution by checking the amount of items in the players inventory using UCC Version is 2.1.10 using:
I want to know how to apply this in UCC Version 2.2.4. I found this solution from another user and I want to know how to apply it to the doc pickup script since it doesn't use "Item."
Doc Pickup script:
UCC 2.2+ Solution:
Code:
private bool ValidateWeaponsInInventory()
{
var maxAmmount = 2;
var weaponCount = 0;
var itemTypes = _itemTypes.ToList();
var inventory = GetComponent<Inventory>();
foreach(var item in inventory.GetAllItemTypes())
{
var match = itemTypes.Contains(item);
if(!match)
continue;
weaponCount += (int)inventory.GetItemTypeCount(item);
}
return weaponCount < maxAmmount;
}
I want to know how to apply this in UCC Version 2.2.4. I found this solution from another user and I want to know how to apply it to the doc pickup script since it doesn't use "Item."
Doc Pickup script:
Code:
using UnityEngine;
using Opsive.UltimateCharacterController.Inventory;
/// <summary>
/// Picks up the specified ItemType within the Start method.
/// </summary>
public class Pickup : MonoBehaviour
{
[Tooltip("The character that should pickup the item.")]
[SerializeField] protected GameObject m_Character;
[Tooltip("The ItemType that the character should pickup.")]
[SerializeField] protected ItemType m_ItemType;
[Tooltip("The number of ItemType that the character should pickup.")]
[SerializeField] protected int m_Amount= 1;
/// <summary>
/// Picks up the ItemType.
/// </summary>
public void Start()
{
var inventory = m_Character.GetComponent<InventoryBase>();
if (inventory == null) {
return;
}
// Adds the specified amount of the ItemType to the inventory.
// m_ItemType: The ItemType to pick up.
// m_Amount: The amount of ItemType to pick up.
// -1: The slot ID that picked up the item. A -1 value will indicate no specified slot.
// true: Should the item be picked up immediately? If false the EquipUnequip ability may not switch to the newly picked up item.
// false: Should the item be force equipped?
inventory.Pickup(m_ItemType, m_Amount, -1, true, false);
}
}
UCC 2.2+ Solution:
Code:
int count = 0;
List<Item> allItems = inventory.GetAllItems();
Inventory inventory = GetComponent<Inventory>();
foreach (Item item in allItems) {
if (inventory.GetItemIdentifierAmount(item.ItemIdentifier) > 0) {
count++;
}
}