I'm making a mobile game, and I want have secondary camera that shows another part of the scene within a box. I'm able to do this easily enough by setting the camera's viewport settings, but the issue I'm having is when you change the screen size, the camera size changes with the screen no longer looking like it shows in the box (The box doesn't expand/contract with the device's screen size). Is there a way to set the camera's size an position relative to a game object? This is what I'm trying to do:
\$\begingroup\$
\$\endgroup\$
3
-
\$\begingroup\$ Presumably you considered writing a script that updates the camera's viewport rect to match your desired size/position/bounds? \$\endgroup\$– DMGregory ♦Commented May 17, 2021 at 4:49
-
\$\begingroup\$ I assumed I'd need to have it update the viewport rect, but how? haha. The viewport rect doesn't really match up 1:1 with the box's size/pos/bounds. The viewport rect values are percentage of the screen, and the box's values are based on the position of where it is in the world. \$\endgroup\$– Vandel212Commented May 17, 2021 at 5:19
-
\$\begingroup\$ So you just convert the absolutes to percentages (or ratios rather, since we're not multiplying by 100), the same way you'd do for other measurements: value / total = ratio. Did you need help with the math? If so, be sure to give us details about what kind of object the black box we need to fit into is. (ie. sprite, UI Image/panel, tilemap, something else...) \$\endgroup\$– DMGregory ♦Commented May 17, 2021 at 10:38
Add a comment
|