Collect Items based on mouse click instead of player interaction

uncamuck

New member
Hello,

I'm trying to figure out where I would implement a script and what function I would call to add a mouse click on an ITEM PICKUP because I don't want to force the player to walk over the item to collect it.

I want to be able to put it on the ITEM PICK UP but I don't know where I would do that.
 
For that you'll need a custom script that raycasts under the mouse to indentify the pickup object.

You can find many tutorials on racyast on youtube. Here is a good introductory video on the subject:
Once you have the pickup component from that raycast simply call OnInteract (you'll need to pass in the InventoryInteractor component.):
Code:
// Here do some raycast to find the pickup component.

// Check that the pickup is not null.
if(pickupHit == null){ return; }

// Then interact with the pickup, from the Inventory Interactor.
// The Inventory Interactor component is usually on the player gameobject
pickupHit.OnInteract(m_MyInventoryInteractor);

Note that if you want to, you can completely bypass our interaction/pickup system and make your own.
Its very simple. All you have to do is add an ItemObject or Inventory component on your custom pickup component and add those items in your player Inventory when you click on it.
You can find code examples of getting and adding items on these pages:

This way you won't need the Interactable or Interactor components which are mainly trigger based.
I hope that helps
 
Top