- Home /
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-
Answer by cncguy · Jul 06, 2010 at 10:06 PM
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 }
Oh sorry I missed the bit about your GUI elements going off the screen. I'll make an edit above. Hang on.
Answer by Tetrad · Jul 05, 2010 at 07:16 PM
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.
Answer by alex 1 · Jul 05, 2010 at 06:50 PM
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
Disabling the resolution dialog will remove the startup dialog that comes with Unity when somebody plays your game. I feel it gives it a more professional feel. You can still change the settings within the game so your not locking yourself out of changing the settings.
That would work if ANY of the setting worked on a laptop but I don't think any of the do! In the editor game view I have it set to 4:3 and for my testers 4:3 is way to big!
Answer by Donato · Mar 12, 2011 at 02:44 PM
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.
if you go to build settings and then player setting it should show you the default screen hight and width