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.
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.
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 .
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?
Make sure that you are using GetComponent<Inventory>() (without any qualifiers, this would be an inventory attached to the GameObject and not player.GetComponent<Inventory>();