Hey guys, I’ve tried every single help information on getting the GUI’s to stay scaled
for every screen resolution, but it just doesn’t work!
I 0 out all the Pixel Insets, change the scale to my liking and position the Joysticks where I want.
Well, what happens is, if I 0 out the Width and Height (In Pixel Inset) I can no longer use the Joysticks.
Well that problems number 1.
Problem number 2 is, they are never scaled with any droid I use.
Figured it might have been my G3 with 4K Resolution, well nope.
I tried with my Ellipsis 7 Tablet at 720P and it’s still not right.
Both Joysticks become super small like they are 5 x 5 in pixels and only take the first half of the screen no matter which device I use.
Please help me guys!
Ok, for different resolutions of the android (or other screens), it is necessary to scale your GUITextures and GUIText. I will write a small explaining script (I write on CSharp):
//define here the original resolution
public float origW = 1280;
public float origH = 720;
void Start() {
float scaleX = (float)(Screen.width) / origW; //your scale x
float scaleY = (float)(Screen.height) / origH; //your scale y
//Find all GUIText object on your scene
//Update 1: for C# add "typeof"
GUIText[] texts = FindObjectsOfType(typeof(GUIText)) as GUIText[];
foreach(GUIText myText in texts) { //find your element of text
Vector2 pixOff = myText.pixelOffset; //your pixel offset on screen
int origSizeText = myText.fontSize;
myText.pixelOffset = new Vector2(pixOff.x*scaleX, pixOff.y*scaleY); //new position
myText.fontSize = (int)(origSizeText * scaleX); //new size font
}
//Find all GUITexture on your scene
//Update 1: for C# add "typeof"
GUITexture[] textures = FindObjectsOfType(typeof(GUITexture)) as GUITexture[];
foreach(GUITexture myTexture in textures) { //find your element of texture
Rect pixIns = myTexture.pixelInset; //your dimention of texture
//Change size pixIns for our screen
pixIns.x = pixIns.x * scaleX;
pixIns.y = pixIns.y * scaley;
pixIns.width = pixIns.width * scaleX;
pixIns.height = pixIns.height * scaleY;
//Sets new rectangle for our texture
myTexture.pixelInset = pixIns;
}
}
That’s all. Attach this script to any object, for example, Main Camera. I hope that it will help you.
Not sure if you’re script helped getting it to work, but I found this one and its working
I APPRECIATE YOUR HELP THOUGH BUDDY!
But here is the code I found that works.
public Vector2 scaleOnRatio1 = new Vector2(0.1f, 0.1f);
private Transform myTrans;
private float widthHeightRatio;
// Use this for initialization
void Start () {
myTrans = transform;
SetScale();
}
// Update is called once per frame
void SetScale()
{
//aspect ratio
widthHeightRatio = (float)Screen.width/Screen.height;
//Apply the scale. We only calculate y since our aspect ratio is x (width) authoritative: width/height (x/y)
myTrans.localScale = new Vector3 (scaleOnRatio1.x, widthHeightRatio * scaleOnRatio1.y, 1);
}
}