Scale sprite to the size of an UI Image.
Hello,
in my project I have a Canvas with an UI Image that scales probally with different screen sizes on mobile.
I would like to use the UI Image position, width and height to display my game sprites. I have 10x10 sprites for a puzzle that I like to be placed and scaled according to the UI Image. That way the sprites would scale correct on different devices.
For some reason I can't get this to work. It seems it isn't easy to get the scale of the UI Image in a correct way.
Did anyone already has experience with this? I'm very new Unity but not new to coding. This scaling I did serveral times in C++ but in Unity it's a different thing - it seems.
Thanks for any hints that push me in the right direction!
Answer by elmo · Oct 04, 2019 at 01:40 PM
Found the solution myself - using GetWorldCorners will give me the correct data of an UI Image.
https://answers.unity.com/questions/885480/46-gui-getting-dimensions-of-2d-ui-object-button-f.html
Thanks! I had the same problem, let's take a look at that solution