Created
January 30, 2015 04:37
-
-
Save chabiribon/09c7315f6d8da8c25ff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Drag : MonoBehaviour { | |
private Vector3 screenPoint; | |
private Vector3 offset; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
void OnMouseDown() | |
{ | |
this.screenPoint = Camera.main.WorldToScreenPoint (transform.position); | |
this.offset = transform.position - Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); | |
} | |
void OnMouseDrag() | |
{ | |
Vector3 Point = new Vector3 (Input.mousePosition.x, Input.mousePosition.y,screenPoint.z); | |
Vector3 tPosition = Camera.main.ScreenToWorldPoint (Point) + this.offset; | |
transform.position = tPosition; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment