Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TouchDrag : MonoBehaviour {
  6.  
  7. void Update() {
  8. if (Input.touchCount > 0) {
  9. Touch touch = Input.GetTouch(0);
  10.  
  11. Vector2 mousePos = Camera.main.ScreenToWorldPoint(touch.position);
  12.  
  13. if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(mousePos)) {
  14. if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) {
  15. Vector2 pos = new Vector2(mousePos.x, mousePos.y);
  16.  
  17. transform.position = pos;
  18. }
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement