- Home /
Spawning Items from In Game Shop and Adding Items to Inventory
I successfully set up my shop, and it works by adding GameObjects (Items) to the Player's Inventory. Unfortunately, I have run into another issue. I am using an ItemManager to spawn prefab clones and then I add those clones to the Player's Inventory and set the world items as not active.
Is there a way to do this without using Instantiate? Or do I have to spawn an item then add it to the layer inventory? Also is setting using SetActive better than using Destroy and Instantiate every time you get rid of and add an item onto the scene?
Answer by Carterryan1990 · Jul 29, 2018 at 07:28 AM
You could instead create a child gameobject on your player and call it a container. Once your player picks up an object/item you would set that object/items parent to the container object along with it’s position. And if you don’t want the object visible just SetAactive(false).I think this is what your asking? If not please elaborate more and I’ll be glad to help.
Public Transform Container;
bool item_should_be_deactived;
void OnTriggerEnter(Collider other)
{
If(other.tag == “itemTag”)
{
PickUpItem(other.gameObject);
}
}
void PickupItem(Gameobject item){
{
Item.transform.setParent(container);
Item.transform.position = container.position;
If(item_should_be_deactived)
{
Item.setactive(false):
}
}
Awesome glad I could help! If you can mark this as answered it would be greatly appreciated!