Hello my inventory system picks up one item but does not pickup any more to fill the other two slots. It is saying the whole inventory is full when it should be one slot is full. Here is my code for the inventory and this is attached to the player.
public class MedInventory : MonoBehaviour
{
public bool[] isFull;
public GameObject[] MedkitSlot;
public GameObject[] BandageSlot;
public GameObject[] CoffeeSlot;
}
This next script is attached to the items you pickup.
public class MedPickup : MonoBehaviour
{
private MedInventory medInv;
public GameObject itemButton;
private void Start()
{
medInv = GameObject.FindGameObjectWithTag("Player").GetComponent<MedInventory>();
itemButton.SetActive(false);
}
void OnTriggerStay2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
GameObject[] targetSlot = new GameObject[0];
bool validItem = true;
switch (gameObject.tag)
{
case "medkit": targetSlot = medInv.MedkitSlot; break;
case "bandage": targetSlot = medInv.BandageSlot; break;
case "coffee": targetSlot = medInv.CoffeeSlot; break;
default: validItem = false; break;
}
if (validItem)
{
for (int i = 0; i < targetSlot.Length; ++i)
{
if (!medInv.isFull[i])
{
medInv.isFull[i] = true;
itemButton.SetActive(true);
Instantiate(itemButton, targetSlot[i].transform, false);
Destroy(gameObject);
break;
}
}
}
}
}
}