How to access RectTransform's left, right, top, bottom positions via code?

Sanath Bharadwaj picture Sanath Bharadwaj · Jun 11, 2015 · Viewed 30.2k times · Source

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?

Answer

maksymiuk picture maksymiuk · Jun 11, 2015

Those would be

RectTransform rectTransform;

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