I'm coming from Libgdx engine to Unity and I'm a beginner programmer. I try to make a game in Unity for Android and iOS devices, but I have a problem with the aspect ratio/resolution scaling. In Libgdx if you have develop something you give a "default" resolution, and everything will be scaled to the device's screen, not matter if it has bigger or smaller resolution, and nothing will be cut off from the screen. On the other side, in Unity if I make a game it will crop the screen to the chosen aspect ratio, which is not the best if you want the same experience across all the devices available. I have searched on the internet for a long time, but I haven't find anything that would work for me.
Bottom line: I would like to know if there's some code for Unity (C#) which will make my game looks like the same across all devices with different aspect ratios? I'm developing with Unity 2D. If anybody could code it and would like to share it, I would be very happy, because it is very bad if it doesn't look like same on all devices. I don't have the problem with onGUI yet, as I haven't did any menu or something for it, just the game, but it is not good that the background is not the same on devices, and that the character is not on the same portion of the screen.
During init, use Camera.pixelRect to determine the Height and Width of the Device assuming the camera is fullscreen.
Store the Height and Width and then do some math with your default settings. Eg. Default settings is 480x854, pixelRect is 800x1280. So difference in width is 800f/480f. Do the same for height.
Use the difference and multiply it to the object at the top of the hierarchy.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With