- Home /
GUI Scaling to fit screen
So I have the following situation and I'm not really sure how to fix it. I want the player to be able to pick different screen sizes and then have the GUI scale to fit those sizes. I'm not sure how to go about this and everything I've tried isn't working.
For example lets say I have a Texture that I would like displayed at 1700, 800 on a 1920 x 1080 screen. How would I go about making it scale for any size?
This is sort of what I have:
void OnGUI()
{
Texture imag;
GUI.DrawTexture(new Rect(1700, 800, image.width, image.height), image);
}
Comment
Best Answer
Answer by Dreamer · Jun 15, 2011 at 02:03 AM
First of all you need to decide a standard resolution for your game and all your gui size is based on it. Let's say you make it 1700 x 800.
var X:float=1700;
var Y:float=800;
void OnGUI()
{
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/X, 1.0*Screen.height/Y, 1.0));
//put all your gui components below:
Texture imag;
GUI.DrawTexture(new Rect(1700, 800, image.width, image.height), image);
}
Your GUI will now fit to any other resolution also.
Your answer