Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent (typeof(BoxCollider2D))]
- public class Draggable2D : MonoBehaviour {
- Vector2 startPos;
- Vector2 offset;
- private void OnMouseDown()
- {
- startPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- offset = (Vector2)transform.position - startPos;
- }
- private void OnMouseDrag()
- {
- Vector2 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- transform.position = p + offset;
- }
- }
Add Comment
Please, Sign In to add comment