Unity3d – How to access RectTransform’s left, right, top, bottom positions via code


I have a UI Canvas with render mode world space set. For all UI elements that belong to this canvas, I am seeing 'left', 'right', 'top' and 'bottom' variables in the RectTransform component in the editor. Any ways to access these variables via code?

Best Solution

Those would be

RectTransform rectTransform;

/*Left*/ rectTransform.offsetMin.x;
/*Right*/ rectTransform.offsetMax.x;
/*Top*/ rectTransform.offsetMax.y;
/*Bottom*/ rectTransform.offsetMin.y;
Related Question