Help with inventory item dropping trigger

,

So, not to overwhelm with detail; I’m trying to have an item appear on a tree once an object from the inventory is place on it.

I thought the easiest way to do this would be to activate a gameobject (the decoration) once a collider has been triggered from dragging a decoration item from the inventory. Unfortunatly the item doesn’t seem to be triggering the collider and I think it has something to do with the inventory dropper script.

 protected virtual Vector3 GetDropLocation()
 {
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hitData;
     Vector3 offset = new Vector3(0, .5f, 0);
     if (Physics.Raycast(ray, out hitData, 1000))
     {
         return worldPosition = hitData.point + offset;
     }
     return transform.position;
 }

This is the code for dropping an item into the world from the inventory.

private void OnTriggerEnter(Collider other)
 {
     //getting all items in array
     //running through each object in array
     if(other.CompareTag("Pickup"))
     {
         foreach (var item in _gameObject)
         {
             for (int i = 0; i < _gameObject.Length; i++)
             {
                 if (isActive == false)
                 {
                     item.SetActive(true);
                     isActive = true;
                     Destroy(other);
                 }
             }
         }
     }
    
 }

And this is for activating the game object.

Any help would be greatly appreciated. Although I’m sure i’ll figure it out as soon as I post this; as is often the case.

Is this the RPG: Inventory that you’re working with by chance?

It might be helpful to see the full script with the OnTriggerEnter in it to get an idea of the setup.

Hi Brian. Thank you for the response. It is indeed working with part of the RPG Inventory.

I realised that I didn’t have a rigidbody on my pickups, so of course triggers wouldn’t be activated.

Thanks

1 Like

That would do it. There must be a rigidbody on one of the two objects involved in a collision or trigger. Good job getting that sorted!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms