Search Unity

Web publish vs Unity game

Discussion in 'Scripting' started by Loff, Sep 22, 2014.

  1. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    Hello!

    In unity the resolution is set to 1366x768 and the GUI etc are all in place, the problem appears when I publish it for web.
    The resolution seems to automaticly set itself to 1600x900 (I believe this is the resolution after testing that resolution in the game room of Unity).
    When the game is running in 1600x900 the GUI doesn't fit where it is suppose too!

    The GUI doesn't seem to rescale/move if I make the web window smaller/larger.


    Any ideas how I can fix it so the resolution is set to 1366x768 ? Thanks!
    I have changed the resolution inside of build/player settings to 1366x768 by the way, no luck.


    After some testing.. it seems that everything in game is scaling with resolution, but not my GUI scripted stuff, any ideas how to easliy make everything scale well without having to rescript all position? /screen_width ?
     
    Last edited: Sep 22, 2014
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Did you try GUI.matrix yet ?
     
  3. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    Never tried it, could that be a good solution? Have to read about it first as well, never heard of it to be honest
     
  4. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    To be honest I don't know all the things that can be done with matrix, but here is an example of one.

    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity,Vector3
    (Screen.width / 1024.0, Screen.height / 768.0, 1));

    Just place it first in the OnGui() function. Hope this helps.
     
  5. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    so basically you have that in your void OnGUI and it should work right away?

    I get some errors thought ( if it was correct to put it into OnGUI).

    By the way I see it says vector3, but I do that really matter even if my game is 2D?

    Errors:
     
  6. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    You may have to c# the example. There shouldn't be any problems with a 2D game, though I never tested a matrix in one.
     
  7. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    Solution:
    Code (CSharp):
    1.  
    2. void OnGUI() {
    3. AutoResize(1366, 768);
    4. }

    Code (CSharp):
    1.  public static void AutoResize(int screenWidth, int screenHeight)
    2.     {
    3.         Vector2 resizeRatio = new Vector2((float)Screen.width / screenWidth, (float)Screen.height / screenHeight);
    4.         GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(resizeRatio.x, resizeRatio.y, 1.0f));
    5.     }
     
    Last edited: Sep 22, 2014
  8. Loff

    Loff

    Joined:
    Dec 3, 2012
    Posts:
    81
    thx for getting me on the right track btw :) didn't know about matrix.