Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scale gameobject fit the screen?

Discussion in 'Android' started by Dzxyan, Jul 8, 2014.

  1. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    How to scale the gameobject to fit the screen if i change my aspect ratio 16:9 to 4:3?
    Really can't find from google,
    any help?
     
  2. trul

    trul

    Joined:
    Nov 15, 2013
    Posts:
    9
    Let's say you want to scale image 1600x900 (16:9) to fit to 800x600(4:3).
    scale.x = 800/1600 = 0.5
    scale.y = 600/900 = 0.66

    Another example.
    If you have original image of 1600x900 and you want to fit it to 4:3 aspect ratio w/o changing its height.
    The new image dimensions will be Wx900.
    H = 900
    W= ?
    H/W = 4/3
    W = H*3/4 = 900*0.75 = 675
    scale.x = 0.75

    Hope it answers your question.
     
  3. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    let say my gameoject is red part like this
    Untitled-1.jpg
    the size is 1600x150
    if changing to 4:3 screen,
    how i should write for that?
    still use your method?
    one more question,
    how to check my screen ratio aspect?
    thanks for reply
     
  4. dwd31415

    dwd31415

    Joined:
    Nov 14, 2013
    Posts:
    25
    To compute the ratio you have to divide Screen.width though Screen.height like this:
    Code (CSharp):
    1. float ratio=Screen.width/Screen.height;
    2.  
     
  5. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    it's always return float 1,
    it will not change whenever i change ratio in game view