Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TouchDrag : MonoBehaviour {
- void Update() {
- if (Input.touchCount > 0) {
- Touch touch = Input.GetTouch(0);
- Vector2 mousePos = Camera.main.ScreenToWorldPoint(touch.position);
- if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(mousePos)) {
- if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) {
- Vector2 pos = new Vector2(mousePos.x, mousePos.y);
- transform.position = pos;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement