So the above question might sound kinda weird so let me go more in depth.
I’ve got these two lists:
public List itemsInInventory = new List(); public List stack = new List();
Now the stack is only called when need to (which is most of the times for this part of the inventory.)
But I don’t know how I can access the right int in this list that works together with the right item so:
itemsInInventory[0] would work together with stack[0] and so on.
Now I got this pickup script on the items to get picked up:
//The part that handles everything that is stackable. else if (item.stackable && Input.GetKeyDown(KeyCode.E) && canPickUp) { inv.item = GetComponent(); Debug.Log("Picked up item!"); CheckIfInInv(); } } void CheckIfInInv() { if(inv.itemsInInventory.Any((myObject) => myObject.name == item.itemName)) { //HERE IT NEEDS TO ADD A STACK transform.SetParent(useableItem); this.gameObject.SetActive(false); this.gameObject.transform.localPosition = new Vector3(0, 0, 0); pickUp.enabled = false; pickUpText.SetActive(false); } else { transform.SetParent(useableItem); this.gameObject.SetActive(false); inv.itemsInInventory.Add(this.gameObject); inv.stack.Add(inv.stack.Count + 1); setImageToSlot = inv.itemsInInventory.Count; inv.slots[setImageToSlot - 1].image.overrideSprite = item.itemImage; pickUpText.SetActive(false); } }
So where I set in caps (sorry) where it needs to add one to the right stack in the list. according to the item which it gets set to. (The item already exists in the list of items when a stack has to be added) Does anyone know how I can access the right stack according to the right item in the list?