I have 2 smartphones 1. Nexus 5 and 2. Samsung Galaxy S3 mini.
I developed a little fun game and now I have a problem…
The the resolution of the two smartphones are different. On my Nexus 5 is the game too small, if I make it bigger, then on my Samsung Galaxy S3 mini is it to big.
Out of curiosity, do you want the resolution to change appropriately for each device it is on or do you want to be sure that the display is somewhat standard for all devices? (in other words can parts of the screen be cut off if the display on the device is too big?) Silly question, but when you say you make the screen size “bigger” how did you do it exactly?
Some screenshots would be helpful, however! If your problem is gui buttons or menu objects then I have the solutions!
If it’s GUI elements that are looking too big or small then you should set the rect to a proportion of the screen rather than x amount of pixels.
Vector2 ButtonSize = new Vector2 (Screen.height * 0.24f, Screen.height * 0.08f);
GUIButton = new Rect (Screen.width * 0.5f - ButtonSize.x / 2, 0, ButtonSize.x, ButtonSize.y);
This makes a decently sized button at the top center of the screen. The reason both X and Y for ButtonSize use screen.height is so that the button will keep it’s aspect ration, otherwise the button will stretch.
If your using objects or sprites on a menu or a set screen and they are being cut off by the end of the screen or appear to far in then this script I wrote will fix that problem:
using UnityEngine;
using System.Collections;
public class Align : MonoBehaviour {
public float Width, Height, Depth;
void Start(){
transform.position = GameObject.Find("Main Camera").camera.ScreenToWorldPoint(new Vector3(Screen.width * Width, Screen.height * Height, Depth));
}
}
This script will move an object when it’s created to wherever you want in screenspace using Width, Height, and Depth. Width is how far along you want the object to appear on the horizontal plain of the screen. 0 is the very left, 1 is the very right. Height is the same as Width but along the vertical plane, 0 being the bottom and 1 being the top. Depth is distance from the camera. This script works best when putting it on a empty object and using that as an offset for it’s child objects. If you wanted your logo made out of a couple of sprites to always appear at the bottom left corner, all you would do is make a empty object and place it at the bottom left of the logo. Then parent the logo objects to it and give it this script with Width = 0, Height = 0, Depth = 10 (or however far away you want it). Note that for this script to work your main camera needs to be named “Main Camera” or you could just change that in the script.