Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class INSERT_SCRIPTNAME_HERE : MonoBehaviour {
- public Transform theDest;
- bool down; //if the mouse is clicked or not
- 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*/
- if(down == true) {
- GetComponent<Rigidbody>().useGravity = false;
- this.transform.position = theDest.position; //moves the object to in front of you
- }
- if(down == false) {
- GetComponent<Rigidbody>().useGravity = true;
- }
- }
- 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*/
- void OnMouseUp() {down = false;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement