# How to calculate the length of a UI element?

Hi, I am currently working on UI element of a 2.5D game. This element indicates to the player how far can his actions reach. For that i am trying to build a system that will change the scale of the element to fit what it needs to be. However for this to work i need to know the length of the element in standard distance units. How can i calculate that?

Edit:
just to clarify the length should be in world-space. For example if the UI element looks to be the same length as a standard unity cube itâ€™s length is 0.5.

You can use width property of RectTransform.rect to get the length of UI element.

I have found a way of calculating the length here it is:

``````	void CalculateBaseLength()
{
// mainCanvas is the rect of the parent of the element i want to measure.
//baseRect is the rect of the element i am trying to measure. This rect must be contained within mainCanvas or this won't work
Vector2 min = Rect.PointToNormalized (mainCanvas.rect,baseRect.min);//calculating were is the bottom left bottom corner of my element compared to mainCanvas
Vector2 max = Rect.PointToNormalized (mainCanvas.rect,baseRect.max);//calculating were is the bottom right top corner of my element compared to mainCanvas
baseLength=max.x-min.x; //The delta of the x position now gives me the length of the element in worldspace!!!
}
``````

If you delta the y you can also get the height of the element in worldspace.