Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class DraggableObject : MonoBehaviour
- {
- bool dragging = false;
- Plane movePlane;
- void OnMouseDown ()
- {
- dragging = true;
- movePlane = new Plane(-Camera.main.transform.forward,transform.position);
- }
- void Update ()
- {
- if (!dragging || !this.enabled)
- return;
- if (Input.GetMouseButtonUp(0))
- dragging = false;
- Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
- float hitDist;
- if (movePlane.Raycast(camRay,out hitDist))
- transform.position = camRay.GetPoint(hitDist);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment