Hello, I'm making a game for android/ios and i want the width to be the same on all phones. I'm using an orthographic camera and here is an image illustrating what i want to do (the black bars are walls and the red squares are the visible area):
Anyone? I have googled for hours now and i can't come up with a solution. There must be way to do this, right? All i want to do is to make it show less/more on the height instead of the width. EDIT: Solved it myself
Code (csharp): Camera.main.aspect = width / Screen.height; Aspect is basically the aspect ratio of the view area which is the width divided by the height.
Can you please show how you solved this? As I now face the same problem with the camera width while working on my game for Android/iOS.
Set the game to a resolution you want the game to look ideal in (for example 480x800) and then zoom the camera so it shows what you want it to show. Now, take ortographicSize/(SceenHeight/ScreenWidth). This will be your constant. Then, simply use this code to set the size: Code (csharp): double size = yourConstant*(camera.GetScreenHeight()/camera.GetScreenWidth());
Oh thanks so much! I think I got it now. As in my case I want to set the game to 720x480, so I did it like this: Code (csharp): Screen.SetResolution(720,480,false); float screenRatio = camera.orthographicSize/(480f/720f); camera.orthographicSize = screenRatio*(camera.GetScreenHeight()/camera.GetScreenWidth()); Am I missing something here? (Didn't test this yet on different devices tho)
screenRatio should be a constant so you need to replace camera.orthographicSize with the size of the camera when it fits the way you want it.
Haha just take a look at my code today and realize I've made this line useless: Code (csharp): camera.orthographicSize = screenRatio*(camera.GetScreenHeight()/camera.GetScreenWidth()); Since nothing can change if I calculate "screenRatio" using "camera.orthographicSize". My bad Will need to take some Maths classes. Thanks again for figuring it out. Cheers!