Adding items to an inventory by clicking on them?

Hello,

I have a question using inventory system in unity. I’m using the same gameobjects, assets, c# script, etc in the same order as in this video: EASY Unity INVENTORY System | Unity Guide | FAST - YouTube

I would like to know if instead of using the squirrel to pickup items I just want to click on them with my PC mouse. What changes I need to make to the inventory script on this video to add items by clicking on them?

I don’t really have time to watch the full 20 min video, (sorry) so I don’t know what you’re referring to when you say you use the ‘squirrel’ to pick up items. If you want to add items to your inventory script using the mouse (e.g. clicking on an object in the scene), you can take a look at a raycast.


it would help to see your script, but you can try this:

void Update()
{
    PickupItems();
}

void PickupItems()
{
    if (Input.GetMouseButtonDown(0))
    {
        // Cast a ray from the camera to where you clicked
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // If the raycast hit something..
        if (Physics.Raycast(ray, out RaycastHit hit))
        {
            GameObject hitObject = hit.collider.gameObject;
            // Add hitObject to inventory...
         }
     }
}

@EdgelessRug