- Home /
How to make game fit all screen Size and Resolutions
Hello I have a simple 3d game for android. It works fine on the Galaxy Tablet and the Note II but when I test it on the Note 4 my formatting (Buttons) was all smaller and not in the correct location. I have a Camera Script that I thought would take care of it which is. My game is in landscape format. Any help would be appreciated.
public class CameraScript : MonoBehaviour {
//define here the original resolution
private float origW = 640f;
private float origH = 320f;
void Start(){
float scaleX = Screen.width / origW; //your scale x
float scaleY = Screen.height / origH;
//Find all GUIText object on your scene
GUIText[] texts = FindObjectsOfType(typeof(GUIText)) as GUIText[];
foreach(GUIText myText in texts) { //find element of text
Vector2 pixOff = myText.pixelOffset; pixel offset on screen
int origSizeText = myText.fontSize;
myText.pixelOffset = new Vector2(pixOff.x*scaleX, pixOff.y*scaleY); //new position
float floatFontSize = origSizeText * scaleX; //new size font in a float
myText.fontSize = (int)Mathf.RoundToInt(floatFontSize); // Closest value of fontSize
}
}
}
Answer by koothur19021 · Jul 05, 2015 at 04:48 AM
if you have problem in fitting the GUI elements in proper form then I suggest you using the anchor points. Basically you have to first of all place the GUI elements like buttons and texts to their position and size after doing that there are 4 anchor points which you have to properly fit on all 4 edges of that particular GUI element, do that in all GUI elements and it will rescale itself in all resoultions.
Hey thank you for the quick response but I have Gui buttons and in the development scene i have no way of setting the anchors in the UI system. because of the gui buttons are coded in my scripts.