- Home /
Adjusting Camera Z Position by Resolution (Canvas Size)
Hi! I need some advice regarding the UI Menu in my game. So, I've created several canvases on a scene and set it all to world space. The idea is that the camera should move around the scene with several canvases representing different menu sections (main, options, new game, etc.). Now I've started to adjust the elements according to the resolution set in settings. Now it does the following: when the game starts it looks for the current resolution and scales all objects according to this resolution by scale ratio (currentResolution/defaultResolution). And it scales fine and looks fine as well.
The problem is with the camera. The idea is to set the camera to focus on the centre of a canvas and hold a certain distance by Z. What I did is I've taken the canvas height (i.e. 720 as in currentResolution (1280x720)) and devided it by two and set Z position to be 1280/2 as well it as Y position of the mainCamera.
The problem is with Z position. It works well with 16:9 aspect ratio but when I change it to, say, 5:4 this Screen.width/2 thing doesn't work correctly. The camera gets too close to the canvas and cuts out some elements and other parts of the UI. How do I set the camera Z position right for every resolution? Or is my approach entirely incorrect?
P.S. I've watched this Unity video on adjustung UI menu to all resolutions but this technique doesn't apply in my case since I have a wrold space menu which is a bit different. The only problem now is this Z position of the camera.
Your answer
Follow this Question
Related Questions
Scaling RectTransform to fit screen size in code 1 Answer
Canvas Scaler settings 0 Answers
Unity UI Button distored 1 Answer
Why my GUI scale is not working? 0 Answers