I’m using Raycasting to pickup items but right now it doesn’t matter how close my player is to the object to be able to pick it up. How can I check the distance between the player and the object?
void PickupWeapon()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.DrawRay(ray.origin, ray.direction * 10, Color.red);
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit) == true)
{
weaponToHold = hit.transform.gameObject;
weaponToHold.transform.parent = hand.transform;
weaponToHold.transform.position = hand.transform.position;
}
}
}