- Home /
Question by
Passero82 · Aug 10, 2016 at 03:28 PM ·
uiscalingrecttransform
How can I find the scaled dimension of a RectTransform?
I am trying to add UI elements at runtime. My canvas is using a CanvasScaler set to "Scale with screen size". I also created a prefab from a RectTransform. I notice that when I instantiate that prefab and request the width, I get the initial width however I want to get the scaled width. I assume that the width hasn't been updated as I haven't run through an update cycle so the canvasScaler hasn't done his work yet however I need to find the new width as I need this for accurate positioning.
This is how my code looks like:
GameObject go = GameObject.Instantiate(uiPrefab) as GameObject;
RectTransform rt = go.GetComponent<RectTransform>();
print(rt.rect.width)
Comment
Answer by SunnyChow · Aug 12, 2016 at 02:57 AM
Maybe you can use GetLocalCorners()/GetWorldCorners(), if you want to do positioning.
sizeDelta just store its original size