I am trying to use the OnDrag event to change a gameobjects position.
I’ve done it before and it worked fine, but this time I can’t get it to be accurate.
The only difference between this project and the others is that this time the canvas is on world space coordinates.
I hava tried this code:
public void OnDrag(PointerEventData eventData)
{
transform.localPosition = eventData.position;
}
and this one:
public void OnDrag(PointerEventData eventData)
{
transform.localPosition = Camera.main.WorldToScreenPoint(eventData.position);
}
and this one:
public void OnDrag(PointerEventData eventData)
{
transform.localPosition = eventData.pointerPressRaycast.worldPosition;
}
and I even tried working with the delta, which gave me the best outcome, but it is still not very good:
public void OnDrag(PointerEventData eventData)
{
Vector3 t = new Vector3(eventData.delta.x, eventData.delta.y, 0f);
transform.localPosition += t;
}
I also tried using the transform.position instead of localPosition, and allot of other combinations, Including stuff that I have never tried before like WorldToViewPort, even though I knew it was a Hail Mary.
I would really appreciate help with this, because the movement is very bad right now, and as far as I know the only thing that has changed from other projects is the world space canvas.