OpenGL97
OpenGL97

Reputation: 289

Unity - different phones sizes

I am using unity for develope to my android phone. I am trying to develope a 2D game. When I put new image(sprite) in my game i can see it fully in unity but when I uploaded the game to my phone, parts of the image are missing from the sides. How can I fit the images sizes on all phones?

I saw the answer for this question but for eclipes java and not unity C#.

Upvotes: 1

Views: 2991

Answers (3)

David
David

Reputation: 16277

In Unity 4.6 version, you can make you UI size adaptive:

  1. Select the canvas where your UI resides
  2. In the inspector, add a component called Canvas Scaler (in 4.6 beta, this is called Reference Resolution component)
  3. Set the reference resolution to the native (or original size) of your sprite/background image
  4. Make sure you choose the right "Screen Match Mode" if the phone's resolution is different.

enter image description here

That is it.

Now no matter how you resize the game view, your sprite can make best fit with it: either fit with the width or height, depending on the phone orientations and aspect ratios. In either case, however, you are guaranteed to see full image, rather than portion of it in your case. See the gif below:

enter image description here

Upvotes: 3

BraveVN
BraveVN

Reputation: 430

Use Screen.width and Screen.height to get the screen size of current device, then check your target phones screen aspect ratio:
For Window Phone, it's 5:3 and 16:9
iPhone: iPhone 3, 4 is 3:2, iPhone 5, 6, 6+ is 16:9
Android phone has many types.
After you get the that, make sure your sprites are designed in exact ratio for your target phones, and it'll be matched with screen.

Upvotes: 0

Burdock
Burdock

Reputation: 1105

Screen.width and Screen.height are the only unity specific methods you need.

Pass in height, width, and position information to your objects based on your screen size.

The harder part learning the gui.

If you need more help with syntax, take a look at unit's gui documentation and tutorials.

Upvotes: 0

Related Questions