Guest User

Untitled

a guest
Nov 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent (typeof(BoxCollider2D))]
  6. public class Draggable2D : MonoBehaviour {
  7.  
  8. Vector2 startPos;
  9. Vector2 offset;
  10.  
  11. private void OnMouseDown()
  12. {
  13. startPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  14. offset = (Vector2)transform.position - startPos;
  15. }
  16.  
  17. private void OnMouseDrag()
  18. {
  19. Vector2 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  20.  
  21. transform.position = p + offset;
  22. }
  23. }
Add Comment
Please, Sign In to add comment