Professional Documents
Culture Documents
Drag UIObject
Drag UIObject
void Awake()
{
rectTransform = GetComponent<RectTransform>(); //Get the RectTransform
component of the attached GameObject
canvas = GetComponentInParent<Canvas>(); //Get the Canvas component of the
attached GameObject
}
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.GetComponent<RectTra
nsform>(), eventData.position, eventData.pressEventCamera, out
originalLocalPointerPosition); //Using the event system to detect what is clicked
on
originalPanelLocalPosition = rectTransform.localPosition;
Debug.Log($"originalLocalPointerPosition={originalLocalPointerPosition};originalPan
elLocalPosition={originalPanelLocalPosition}; ");
// Debug output
Debug.Log($"Drag - LocalPointerPosition: {localPointerPosition}, Offset:
{offsetToOriginal}, New Position: {rectTransform.localPosition}"); //Comment out
this line if not debugging an issue, otherwise it will flood the console
unnecessarily
}
}
}