Advertisement
Guest User

unity

a guest
Apr 3rd, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class INSERT_SCRIPTNAME_HERE : MonoBehaviour {
  6.     public Transform theDest;
  7.     bool down; //if the mouse is clicked or not
  8.     void Update() { /*I used the Update() function to always move the object. So if the object DOES fly away it will just teleport back. This also keeps the rotation of the object so looks like you're actually picking it up instead of fixing it onto your FOV*/
  9.         if(down == true) {
  10.             GetComponent<Rigidbody>().useGravity = false;
  11.             this.transform.position = theDest.position; //moves the object to in front of you
  12.         }
  13.         if(down == false) {
  14.             GetComponent<Rigidbody>().useGravity = true;
  15.         }
  16.     }
  17.     void OnMouseDown() {down = true;} /*these two tell if the mouse is clicked or not, they are also necessary for only selecting only one object for some reason*/
  18.     void OnMouseUp() {down = false;}
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement