Hello. I have read all over. I have been working with the following code to get on of my ui images to move back and forth with the click and drag of my mouse. It works so far, the problem in that when I click on the ui image, there is an offset position because when I click on the image , i click a different place every time to drag it.
public void OnDrag(PointerEventData eventData)
{
Vector2 positionMid = eventData.position;
float changeInPositionX = positionMid.x - lastPos.x;
float changeInPositionY = positionMid.y - lastPos.y;
img.transform.position = new Vector3(img.transform.position.x, img.transform.position.y + changeInPositionY, 0);
lastPos = positionMid;
}
This code works. What I really need to know is when I click down on a ui object, I want to know the exact position in relation to that object that I clicked. Like say my ui object that I clicked has a width of 200 and height of 200, if I click within thoughs bounds I want to return the hit coordinates within a 200 x 200 range.
I also looked into ray casting and got 2dray casting working with my ui and added a collider to my ui. But I still cannot get these coordinates.
Can anyone help thanks, I am stumped!