pick up item problem

Hello, I’m having some problems with a pick up script. This is the script I’m using:

// Place this script on the object to be picked up. The object should have a rigid body component.
// Tag the Player Controller with "Player".

var pickupDistance = 3.0;
var heldObject : GameObject;
static var itemHeld = 0;
var objectDist = -.1;
private var hand :GameObject;

function Start() {
    hand = gameObject.FindWithTag("Player");

function Update () {
    if (Input.GetMouseButtonDown(0) && itemHeld == 2) {
        heldObject.transform.parent = null;
        heldObject.GetComponent(Rigidbody).isKinematic = false;
        heldObject = null;
        itemHeld = 0;

function OnMouseDown() {
    if(itemHeld == 0) {
        heldObject = gameObject;
        heldObject.transform.parent = gameObject.FindWithTag("Player").transform;
        heldObject.GetComponent(Rigidbody).isKinematic = true;
        var handLocation = Vector3(0,objectDist,2);
        heldObject.transform.localPosition = handLocation;
        itemHeld = 1;

function OnMouseUp(){
    if(itemHeld == 1)
      itemHeld = 2;

when i attach it to the mesh and whatnot and try to pick it up in play mode, it just disappears… is there a setting I need to adjust?

It depends on your character. The object will be held at this position relatice to your characters pivot:


So it’s always 2 units infront of you (z direction) and, if you haven’t changed the objectDist, 0.1 units above your pivot. Maybe your character isn’t rotated the right way or it’s attached too low. You can switch to the scene view while in playmode (or place both views next to each other) so you can check if it has been attached correctly.