Automatic Screen Resize

Hey All,

I was wondering how I would automatically re size the window so that it fits in the screen... I have a large computer, but my friends (and a lot of other people) have laptops and the buttons and text run off the screen! Is there a way to re size the screen, depending on the screens maximum size, so that they can see everything I see... Any Help Is Appreciated!

-Gibson of GBSoftware-

Hi when I maximise my application I use:

Screen.SetResolution (Screen.currentResolution.width, Screen.currentResolution.height, true);

this maximises the unity application and sets the resolution to the current desktop resolution.

Screen.currentResolution returns the current desktop resolution of the machine.

true/false sets the fullScreen state.

you can then go back to windowed with:

Screen.SetResolution (1024, 768, false); //enter you desired resolution

To switch between fullScreen and not only you can use:

Screen.fullScreen = true/false;

[EDIT 1] To make sure that your GUI resizes to the new resolution:

function OnGUI()
{
var oldMatrix : Matrix4x4;
var tMatrix : Matrix4x4;
var width : int = 1024; //Reference resolution
var height : int = 768; //Reference resolution

oldMatrix = GUI.matrix; //Store current matrix
tMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/width, 1.0*Screen.height/height, 1.0)); //Construct matrix to scale to actual view size
GUI.matrix = tMatrix; //Set the GUI matrix to the scaling matrix

drawYourGUIElementsToSuitReferenceResolution(); //as the function says;)

GUI.matrix = oldMatrix //Set the original matrix back
}

Are you talking about the window itself being larger than the screens, or are you talking about the resolution being reduced but all your 2D GUI stuff being off screen?

If it's the latter, you'll have to use some special code to make your UnityGUI stuff resolution independent.

See here: http://forum.unity3d.com/viewtopic.php?p=91926

You will need to disable the resolution dialog.

You can do this by going into 'Edit' on Unity. Then select 'Project settings' then 'player' then click Display Resolution Dialog 'Disabled'

Alex

I have try to insert in the Awake of my script this instruction:

Screen.SetResolution (Screen.currentResolution.width, Screen.currentResolution.height, true);

for to play with current desktop resolution my game.

But nothing!!!

It start to resolution 1024x768 that is to default from :

File/BuildSetting/PlayerSetting/"Resolution"

WHY it think that my desktop resolution is 1024x768? There is a way for to start before this script and next the setting of Unity?

Ps. I have disable DISPLAY RESOLUTION DIALOG.