1

I'm trying to set up a GUI menu in Unity that will work for all devices. So I started it in setting it up for one resolution that is: 1024 * 600.

It looks ok on that, so I tried adding a scaler to make it look ok on all the rest to.

Example of my code for getting scaler:

float originalWidth = 1024;
float originalHeight = 600;     
Vector3 scale;
scale.x = Screen.width/originalWidth; 
scale.y = Screen.height/originalHeight; 
scale.z = 1;

Then I resize every element with that scale like that:

rect = new Rect(width/2 - 65 * scale.x, height/2 - 50 * scale.y, 130 * scale.x, 65 * scale.y);

But it just doesn't look the same. I also tried like that:

rect = new Rect((width/2-65) * scale.x, (height/2-50) * scale.y, 130 * scale.x, 65 * scale.y);

but it just looked even more wrong.

So to be clear I would like my element to be in the middle of screen with some offset and look the same on all devices.

The biggest problem is when 2 elements needs to be aligned to each other perfectly.

2 Answers 2

1

You could set up a GUI Matrix at your native GUI resolution...

float rx = Screen.width / 1024.0f;
float ry = Screen.height / 600.0f;  
GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(rx, ry, 1));

http://docs.unity3d.com/Documentation/ScriptReference/Matrix4x4.TRS.html

Sign up to request clarification or add additional context in comments.

Comments

0

Use percentages of the screen as positions and sizes for GUI elements:

GUI.Box(new Rect(Screen.width*0.40f, Screen.height*0.4f, Screen.width*0.20f, Screen.height*0.20f));

1 Comment

The problem with that solution is that it's realy hard to position elements in relation to each other, plus it scales images in unusual way...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.