I'm working on a point-and-click adventure game using Unity2D for mobile devices and possible PCs and I'm trying to wrap my head around supporting devices with different screen sizes and aspect ratios.
My background images are high quality and quite large (let's say 4096 x 3072), and I'm trying to scale them down to at least fit into the viewport. However, try as I may, the scaled image always seems to end up either too large for the viewport or much too small.
I'm using an ortographic camera that automatically adjusts its size based on the current screen size using the formula
(Screen.height / 2f) / 100.
To scale down my Sprites, I'm using the following code:
float scaleY = background.renderer.bounds.size.y / Globals.camera.rect.height; float inverseY = 1/scaleY; background.transform.localScale = new Vector3 (inverseY , inverseY);
This results in a background that is way too small to work with. Removing the inverse only serves to make the background massive.