Search Unity

How to adjust the width and height of Sprites according to different resolutions?

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by zyonneo, Oct 2, 2019.

  1. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    241
    This always confuse me.

    How to adjust the sprites for different screen resolutions?

    [Case of UI not sprites]
    Similarly I have tried to adjust the UI also.From other forums they tell me to adjust the following settings 1) Render Mode - Screen SpaceOverlay 2)Scale With screen size 3)Give a reference solution for the device we are trying 4)Match width and height adjust to 0.5.(edited)

    Even though I adjust like these some UI elements having width will look awkward in portrait screen(screen with height regular mobile screen) or UI elements with height will look awkward in landscape(screen with width like ipads).

    [Case of sprites given below]
    I am getting screenwidth by the following method
    Code (CSharp):
    1.  public static float GetScreenToWorldWidth
    2.     {
    3.         get
    4.         {
    5.             Vector2 topRightCorner = new Vector2(1, 1);
    6.             Vector2 edgeVector = Camera.main.ViewportToWorldPoint(topRightCorner);
    7.             var width = edgeVector.x * 2;
    8.             return width;
    9.        
    10.         }
    11.     }
    So if I have a sprite of pixel 1210 x 2048 and I have changed the pixel per unit of the sprite into 1210.Now the sprite in my scene view has become really small.(Initially I used 100 which looked ok in my scene).How to use the above method to set it for different screen resolutions.
     
    Last edited: Oct 11, 2019
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,283
  3. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    295
    No worries. I'll just move the thread to the correct uGUI forum.
     
  4. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    241
    Updated the question.Any help