Hi Guys,
I want to edit the size of a UI panel, and I’d like to do this in code.
How do I find the size of a UI panel (4.6+), and how do I edit it?
I’ve tried:
void OnEnable()
{
if (bInitialised)
{
RectTransform rect = transform.parent.GetComponent<RectTransform>();
RectTransform thisrect = GetComponent<RectTransform>();
Debug.Log("rect sizeDelta: " + rect.sizeDelta);
Debug.Log("rect localScale: " + rect.localScale);
Debug.Log("thisrect sizeDelta: " + thisrect.sizeDelta);
Debug.Log("thisrect localScale: " + thisrect.localScale);
}
}
I’ve found that the object itself has a width, but no height (apparently), and it’s parent (which is a mask for the child object), has no size at all. However you can see them in the game, so you know they DO have a size.
Debug Output
rect sizeDelta: (0.0, 0.0)
rect localScale: (1.0, 1.0, 1.0)
thisrect sizeDelta: (0.7, 0.0)
thisrect localScale: (1.0, 1.0, 1.0)
All I’m trying to do is make the child object exactly match the size of the parent mask object. The issue being that anything inside a mask doesn’t scale alongside every other UI object in the 4.6 UI system.
Does anyone know how to edit them and find their size in script?
Thanks!