How to get current height of button

I have the following code which hard codes the button size to 50:

btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50);

I actually want to get the current height of the button and add 10 to it’s size, but not quite sure how to do that. So something like this:

btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, currentHeightOfButton + 10);

Well thank God for autocomplete … I figured it out:
btnTr.rect.height

So

btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, btnTr.rect.height + 10);
1 Like