using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class UIDragableObj : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler { [AutoUI] public Vector2 position; protected Vector2 error_pos; protected RectTransform rectransfrom; protected void Awake() { rectransfrom = GetComponent(); } // Use this for initialization void Start () { } // Update is called once per frame protected void Update () { rectransfrom.anchoredPosition = position; } public void OnPointerDown(PointerEventData eventData) { print("OnPointerDown"); Vector2 n_position = eventData.position - new Vector2(Screen.width, Screen.height) / 2; error_pos = n_position - position; } public void OnDrag(PointerEventData eventData) { Vector2 n_position = eventData.position; position = n_position - new Vector2(Screen.width, Screen.height) / 2 - error_pos; } public void OnPointerUp(PointerEventData eventData) { error_pos = Vector2.zero; } }