I have UI elements (image, etc). Canvas attached to camera.
There is a RectTransform, but how to convert this data to screen or world coordinates and get center point of this image?
Tried RectTransform.GetWorldCorners but it returns zero vectors.
yourRectTransform.rect.center for the centre point in local space.
yourRectTransform.TransformPoint to convert to world space.
It is odd that RectTransform.GetWorldCorners doesn't work as stated. Per one of the other answers you need to call after Awake (so layout can occur).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With