How to pick up objects

Hi guys I try to make a script to pick up objects, first I made this one which worked but picked up the object from anywhere:`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickUp : MonoBehaviour {

public GameObject item;
public GameObject tempParent;
public Transform guide;

// Use this for initialization
void Start () {

	item.GetComponent<Rigidbody>().useGravity = true;

}

// Update is called once per frame
void Update () {
	
}

void OnMouseDown()
{
	item.GetComponent<Rigidbody>().useGravity = false;
	item.GetComponent<Rigidbody>().isKinematic = true;
	item.transform.position = guide.transform.position;
	item.transform.rotation = guide.transform.rotation;
	item.transform.parent = tempParent.transform;
}

void OnMouseUp()
{
	item.GetComponent<Rigidbody>().useGravity = true;
	item.GetComponent<Rigidbody>().isKinematic = false;
	item.transform.parent = null;
	item.transform.position = guide.transform.position;
}

}Imade a empy gameobject and addet to the player and used it as the tempParent and guide. Then I tried this one which didnt workusing System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pick : MonoBehaviour {

public GameObject item;
public GameObject tempParent;
public Transform guide;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
	}

private void OnTriggerEnter ()
{
	if(Input.GetMouseButtonDown(0)){
			item.GetComponent<Rigidbody>().useGravity = false;
	        item.GetComponent<Rigidbody>().isKinematic = true;
	        item.transform.position = guide.transform.position;
	        item.transform.rotation = guide.transform.rotation;
	        item.transform.parent = tempParent.transform;
			}

}
private void OnTrigerStay ()
{
	if(Input.GetMouseButtonDown(0))
	{
	    item.GetComponent<Rigidbody>().useGravity = true;
	    item.GetComponent<Rigidbody>().isKinematic = false;
	    item.transform.parent = null;
	    item.transform.position = guide.transform.position;
		}
}

}
`
please reply.

OnTriggerEnter() is only called in the specific frame when the collision happens. So you can’t really use it for inputs. If you are clicking on objects with the mouse to pick them up you might use something like this.

using UnityEngine;
using System;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    public GameObject handItemSlot;
    GameObject objectHit;
    Camera mainCamera;
    Rigidbody rb;

    void Start()
    {
        mainCamera = Camera.main;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                objectHit = hit.transform.gameObject;

                //Drop any items already in the handItemSlot
                if (handItemSlot.transform.childCount > 0)
                {
                    foreach (Transform child in handItemSlot.transform)
                    {
                        child.transform.parent = null;
                        rb = child.GetComponent<Rigidbody>();

                        if (rb)
                        {
                            rb.isKinematic = false;
                            rb.useGravity = true;
                        }
                    }
                }

                //Pick up new item
                rb = objectHit.GetComponent<Rigidbody>();

                if (rb)
                {
                    rb.isKinematic = true;
                    rb.useGravity = false;
                }

                objectHit.transform.parent = handItemSlot.transform;
                objectHit.transform.localPosition = Vector3.zero;
                objectHit.transform.localRotation = Quaternion.identity;
            }
        }
    }
}

@urooba ;@duck ;@aldonaletto ;@Bunny83 ;@clunk47 ;@tanoshimi