Adding inventory items to a loot window

I am having difficulties, figuring out how to add items. To a new loot window. To act as a loot drop for the player. Any help and advice will be great

  public void RandomDrop()
        {
            //var baseStats = GetComponent<BaseStats>();

            var drops = dropLibrary.GetRandomDrops(8);
            foreach (var drop in drops)
            {
                inventory.AddToFirstEmptySlot(drop.item,drop.number);
            }
        }

public class LootBox : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        var player = GameObject.FindGameObjectWithTag("Player");
        if (other.gameObject == player)
        {
            if (Input.GetKey(KeyCode.E))
            {
                FindObjectOfType<ShowHideUI>().ShowOtherInventory(gameObject);
            }
        }
    }
}

If I recall from previous conversations, you’re looking for the drops from an enemy to be in a single container rather than scattered about the ground…

You’ll need a container gameobject… this could be the enemy with an Inventory attached, or you could drop a physical object. Either way, this gameobject will need an Inventory, and some way of triggering to open the other inventory.

The itemDropper on the enemy will need a link to the inventory on the container… if it’s on the player already, it’s… GetComponent(); If it’s on a separate container, it’s container.GetComponent.Inventory();

I’m… not sure what’s going on with the Lootbox OnTriggerEnter… the only way it would actually fire is if the player is holding the E key at the exact moment that it walks into the lootbox. You should be able to eliminate the if(Input.GetKey(KeyCode.E)) altogether from the script and just do the FindObjectOfType().ShowOtherInventory.

Yes I understand all that, I want to know, how to populate the inventory with items. How do I go about doing that .

The first script should populate the inventory with random items. You just need to make sure that the variable inventory is set to the inventory on your loot box.

So you mean, to populate it I should just call the function random drop?. In editor? . Or at runtime.

Presumably, at runtime, when the enemy dies?

It’s not the enemy, I want to fill the loot box. An actual game box when the player can come and take random loot from it.
How can I fill it up before runtime. And be saved .

So the Lootbox will need an inventory attached. The Inventory will save itself.
It will need a SaveableEntity (so that it can save itself)

I would have the LootBox call the RandomDropper.RandomDrop in Awake();

That’s pretty much it.

Thanks I will try it out

It’s adding items to the player inventory. How can I individualize it to only go for loot inventory?

Could you be more specific? Are you saying that the RandomDropper is putting the items directly in the player inventory, or that the InventoryUI for the lootbox is displaying the Player’s inventory instead?