I've been working on this 2 d project and it requires a set 14:8 aspect ratio because all of the levels are 14 blocks by 8 blocks. I have it set to 14:8 in the game view so when I test it it looks fine. But, when I build it it scales up to fit the window. This is a problem because when the player goes out of certain boundaries, it stops which looks weird when the screen is wider. I have tried messing around with the resolution and presentation window in player settings (e.g. making it full screen on default, resolution 1400 : 800, changing supported aspect ratios) but nothing worked. I know i could probably set the boundaries wider but it might still look weird on different computers. Also I would preferably not change all the levels to make them 16 : 10 or something. Is there any way to make it look somewhat like the 1st picture on build? Thanks!
I have somewhat of a cheat for this, I'm not sure where I got it, but it is something I use when I want fast results. No matter what it will override the camera and add black bars for screens that don't support the resolution. Just change targetaspect to 14.0 / 8.0 and you should be good to go! Then attach this script to your camera. Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraAspect : MonoBehaviour { // Use this for initialization void Start () { // set the desired aspect ratio (the values in this example are // hard-coded for 16:9, but you could make them into public // variables instead so you can set them at design time) float targetaspect = 16.0f / 9.0f; // determine the game window's current aspect ratio float windowaspect = (float)Screen.width / (float)Screen.height; // current viewport height should be scaled by this amount float scaleheight = windowaspect / targetaspect; // obtain camera component so we can modify its viewport Camera camera = GetComponent<Camera>(); // if scaled height is less than current height, add letterbox if (scaleheight < 1.0f) { Rect rect = camera.rect; rect.width = 1.0f; rect.height = scaleheight; rect.x = 0; rect.y = (1.0f - scaleheight) / 2.0f; camera.rect = rect; } else // add pillarbox { float scalewidth = 1.0f / scaleheight; Rect rect = camera.rect; rect.width = scalewidth; rect.height = 1.0f; rect.x = (1.0f - scalewidth) / 2.0f; rect.y = 0; camera.rect = rect; } } } Hope this helps!
You're a life saver. I was going crazy because I thought I wasn't going to be able to upload my game that I've worked really hard on. Thanks to you this quick fix was exactly what I needed. From bottom of my heart thank you, friend.