• Как сделать перемещение объекта мышью/пальцем?

    @au56
    public class Movement : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
    {
        private Vector2 lastMousePosition;
        private Vector2 currentMousePosition;
    
        public void OnBeginDrag(PointerEventData eventData)
        {
            lastMousePosition = eventData.position;
        }
    
        public void OnDrag(PointerEventData eventData)
        {
            currentMousePosition = eventData.position;
            Vector2 difference = currentMousePosition - lastMousePosition;
            Vector3 newPosition = transform.position + new Vector3(difference.x, difference.y, transform.position.z);
            Panel.transform.position = newPosition;
            lastMousePosition = currentMousePosition;
        }
    }
    Ответ написан
    Комментировать