- Home /
 
New UI Drag Event
I need to drag a new UI Image object on the screen. The Image lives in a canvas. The canvas has a canvas scaler on it so it will work on different resolutions.
I have added an EventTrigger to the image object. In my custom script I have a method called OnDrag (BaseEventData eventData). I then cast that to a PointerEventData.
I use the PointerEventData.delta and add that to my RectTransform anchoredPosition value.
This moves my image object, but the scaling is off. In the editor it is not enough, so I multiply the delta by 1.8 and this seems to make it just right.
When I built for Android, however, the delta was too much and the image went too far as I dragged it.
So my question is how do I properly use the PointerEventData on different devices so that it will move the Image object the correct amount?
Answer by rakkarage · Feb 17, 2015 at 02:57 PM
are you using [canvas scaler - scale with screen size]?
 _scaler = GetComponentInParent<CanvasScaler>();
 ...
 if (_scaler != null)
     Drag(e.delta.x * _scaler.referenceResolution.x / Screen.width);
 else
     Drag(e.delta.x);
 
              Your answer
 
             Follow this Question
Related Questions
A node in a childnode? 1 Answer
Limiting an inventory system + dragging items in inventory window... 0 Answers
UI drag and drop 1 Answer
Create big city for car game? 2 Answers
Fading Out UI On Play 1 Answer