How to get the rendered size of an image on screen? (In absolute pixels that changes based on resolution)
What I'm trying to achieve:
I have an image area (200x200 px), and the user needs to stay in this area with a character for a couple of seconds (while he gets random pushes to the side). The problem is that this area is scaling with resolution of course, so I need to use a relative speed for the movement, I can't just declare to move 2 pixels when the arrow key is pressed, because on a small resolution that will quickly reach the bounds.
So I need to know the exact rendered size in pixels to go forward.
I tried rect transform and scale, those does not change based on resolution. I also found the Renderer.bounds can be an option but this image is using Canvas Renderer, that does not have a bounds property. I'm totally lost now :(
Answer by Uristenzor · Jul 30, 2020 at 09:25 PM
My workaround is born:
Get the current screen size with Screen.width and remember how big the image is in the editor (basically fullhd) and just divide it in the code.
Shrink the 200 px to 192 in the editor so it 1/10th of the native screen, so the render size will always be Screen.width/10. This works.
Your answer
Follow this Question
Related Questions
How do I make the game to auto scale? 0 Answers
Scale to resolution but not window size 0 Answers
RectTransform size aspect ratio 0 Answers
How to dynamically scale an object to a fixed, predefined size at runtime? 0 Answers
Reset (or change Pivot of) an Image in ScrollRect when scaling down 1 Answer