First of all, i’m new to Unity scripting and my head is going to explode, so forgive and correct as you see fit any mistakes I made here. =)
I’ve been searching a lot and still get confused.
My goal is changing the width of the main camera so it’s at the same resolution than when playing fullscreen or hitting the Play button. Let’s say I have a background of 512x256 which I want to be taken as reference for a full camera and screen resolution. I imported it as object set to 100 Pixels to Units (this would be 5.12 x 2.56 World units, right?). I have the main camera size at 1.28, which is half the height (256/2), so this should be right. Now the idea is the screen, editor and game resolution to be the same for the WIDTH.
But first, how to set the camera width properly so it encloses the 512 pixels of the background?. I’ve read this depends on the aspect ratio.
The aspect ratio is width divided by height, so in my example case:
Aspect ratio = 512/256 = 2.
Then, what I do this this number?
camera.pixelWidth is read only, so I can’t modify the width this way…
it seems camera rect it’s only used to show a portion of the screen (modifying only the viewport if i’m not mistaken), being the maxium x value 1, that would be the full width… so this won’t allow me to increase and display the intended screen width size in the viewport, editor and game…
I attacheded a small script with this one in the camera to set it at 512x256 but i can’t see any change neither in the viewport nor when i hit play, it’s all just zoomed in (even when creating a 512x256 resolution in the Game tab dropdown menu).
EDIT: I could get the camera width to fit perfectly to 512 pixels if I set the Viewport Rect W to 1.5 in the Inspector, but I don’t know why this number works. Even though, When I hit Play, the screen is zoomed in and doesn’t display the full background.
So… i can’t figure out:
- Why setting Viewport Rect W to 1.5 worked?
- How to show the full background when I hit play?
Some related bonus questions:
-
Would i need to use “camera.aspect” to set a proper aspect ratio for the width and height if I want the game objects to display properly on mobile devices?
-
How does the current monitor resolution affects to what the Editor, viewport and Game tab display?
-
If I play a 512x256 game on a 1024x768 resolution, I understand the aspect ratio will change so the game object will look distorted. Any way to mitigate this so it looks okey?
Thanks for reading until this point and I would appreciate if only you ask one of this questions =)