title: Picking up and moving objects around
body: <p>I try to find  any example in c# to pick an object into the player´s hand position and moving around. Then when the button is released, the object is dropped.I have found an example in a unity forum, but its in <a href="http://answers.unity3d.com/questions/186414/how-do-i-make-my-fps-character-grab-objects.html" rel="nofollow noreferrer">javascript</a> , how can I implement this in C# </p>
  
  <p>This is the code I found, but I need to grab it when the button is clicked and the player need to be in front of the object.</p>
  
  <pre><code>#pragma strict
  
  var TheSystem : Transform;
  var Distance : float;
  var MaxDistance : float = 10;  
  
  function Update() {
  
  
  
         var hit : RaycastHit;
       if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
       {    
          if(hit.transform.gameObject.tag == "sword2"){
  
  
           Distance = hit.distance;
           if (Distance &lt; MaxDistance){
  
  
               if (Input.GetKeyDown(KeyCode.E)) {
                  // show
               renderer.enabled = true;
               Destroy (GameObject.FindWithTag("sword2"));
                    } 
  
              if (Input.GetKeyDown(KeyCode.Backspace)) {
              // hide
              renderer.enabled = false;
                   }
  
            }
        }
    }
    }
  </code></pre>
  
  <p>I have trid this c# example but it drag . I need to find the way to get it on the empty object when I grab in to the main camera and I need to change to grab in to an empty object inserted on the player position </p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class drag : MonoBehaviour {
  float distance = 10;
  void OnMouseDrag(){
      Vector3 mousePosition = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, distance);
      Vector3 objPosition = Camera.main.ScreenToWorldPoint (mousePosition);
      transform.position = objPosition;
  }
  }
  </code></pre>