1
votes

I am trying to make my 1st game in unity. I need to support different resolutions of android and iOS. The problem is when i place the background image for any one res ex. 1536x2048,It doesn't displays properly for 640x960. The screen size is varying, but sprites and bg sprite is not scaling as per res.

I am not clear how to acheive it. But, it must be a basic thing as there are so many games on android and all phones have different res. and dpi.

There should be some formula or we just need to set orthographic.size for this. I am using this :

// to calc size

Camera.main.orthographicSize = Screen.currentResolution.height / (2*70); //
Camera.main.orthographicSize = Screen.currentResolution.height / 2;
Debug.Log("Camera size :" + Camera.main.orthographicSize); 
Debug.Log("Width : " + Screen.currentResolution.width + " height : " + Screen.currentResolution.height);

// this doesnt give me width and height as per resolution of screen for ex. for 1536x2048 -> i get, Width : 1366 height : 768

i found this as similar question

http://forum.unity3d.com/threads/orthographic-screen-size.113641/ but it didnt help, whereas problem is nearly same.

If somebody can share how to get correct screen resolution by code and how to set width of bg sprite and other sprite, it can solve the problem OR

if there is some setting which takes the default scene and scales automatically for various resolution. it will help.

1

1 Answers

1
votes

Unity does not scale like that. Instead, we design assets to suit our needs. You are using a formula but i don't know what you expect from it. here's some info: Orthographic size is height of view port. Taking your example, for height of 2048, camera size is : 2048/2/100=10.24. This will be maintained irrespective of device screen size. Only difference being it will be less detailed on smaller devices, kind of like a zoom out effect. Now for width,i'm not sure for portrait, but let's say 9:16 is the widest. So if you design the bg for this aspect ratio, the bg will be cropped on smaller devices, shown full on 9:16 devices. To design for this aspect ratio, your bg needs to be 9/16*10.24*100=576 px. (Again i'm not sure which aspect ratio is widest in portrait mode). Hope that helps