Here is what I’m trying to accomplish, I have an item pickup that should only be found once, so I want the script to check the player’s inventory to make sure the player doesn’t already have the item.
If the player has the item the item should disable itself.
Here is the script I have, but I can’t figure out why it’s not working. It doesn’t seem to be actually finding the player’s inventory, but as far as I can see everything is right. I’ve been reading documentation and trying it different ways for about 5 days now with no joy.
Any help would be greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Tools;
using MoreMountains.InventoryEngine;
using UnityEngine;
namespace MoreMountains.CorgiEngine
{
public class PlayerHasItemChecker : MonoBehaviour
{
[Header("ItemName")]
/// the string that holds the name given in the inspector, used to check for the item in the inventory
public string ItemCheckID;
/// the method that should be triggered when the item is checked
public List<int> _ItemList;
public void Start()
{
CharacterInventory CurrentInventory = LevelManager.Instance.Players[0].GetComponent<CharacterInventory> ();
if (CurrentInventory == null)
{
return;
}
_ItemList.Clear();
_ItemList = CurrentInventory.MainInventory.InventoryContains("ItemCheckID");
if (_ItemList.Count == 0)
{
return;
}
else
{
gameObject.SetActive(false);
}
}
}
}
Thanks.