I’m trying to change the Pivot of a RectTransform during runtime, which works perfectly when the Object is not rotated. Unfortunatly the Object has to be rotateable and that’s when a problem arises, when changing the Pivot of the rotated Object it jumps to an incorrect Position.
Can someone point me in the right direction?
Code I’m using:
public void changePivot(Vector2 pivot)
{
Vector2 deltaPivot = pivot - RectTransform.pivot;
float deltaX = deltaPivot.x * RectTransform.sizeDelta.x * RectTransform.localScale.x;
float deltaY = deltaPivot.y * RectTransform.sizeDelta.y * RectTransform.localScale.y;
Vector3 deltaPosition = new Vector3(deltaX, deltaY);
RectTransform.pivot = pivot;
RectTransform.localPosition += deltaPosition;
}