title: Grab objects in Unity like half life 2
body: <p>I am doing a little, but I do not really understand the scripts. I want grab objects ingame like portal or half life 2 and I was trying to code a little script for that action. I made this:</p>
  <pre><code>using System.Collections.Generic;
  using UnityEngine;
  using System;
  
  public class PIckUp : MonoBehaviour {
  
      public Transform theDest;
  
      void OnKeyDown()
      {
  
          GetComponent&lt;Rigidbody&gt;().useGravity = false;
          this.transform.position = theDest.position;
          this.transform.parent = GameObject.Find(&quot;Destination&quot;).transform;
  
      }
  
      void OnKeyUp()
      {
  
          this.transform.parent = null;
          GetComponent&lt;Rigidbody&gt;().useGravity = true;
      }
  
      private void Update()
      {
  
          if (Input.GetKeyDown(KeyCode.F))
          {
              OnKeyDown();
          }
  
          if (Input.GetKeyUp(KeyCode.F))
          {
              OnKeyUp();
          }
  
      }
  
  }
  </code></pre>
  <p>I attach this script to empty object called Destination, when I add a component in grabbable object in &quot;theDest&quot; I target Destination. If i press F all objects are flying i no need aim to them and deform all boxes too i leave here a picture.</p>
  <p><a href="https://i.stack.imgur.com/ufZIz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ufZIz.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/XhFDH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XhFDH.jpg" alt="enter image description here" /></a></p>
  <p>I dont find a easy solution, i follow this scripts but are to complex for me and i dont understand how use them or how attach them to a player or object.</p>
  <p><a href="https://answers.unity.com/questions/1459773/picking-upholding-objects-portal-style.html" rel="nofollow noreferrer">https://answers.unity.com/questions/1459773/picking-upholding-objects-portal-style.html</a></p>