Questions about scaling in a 2d game in unity

by Daniel Bak   Last Updated April 20, 2015 22:05 PM

Okay, so:

I am making an android game. I want everything to scale to the size of the screen I'm using. Further, my static background needs to scale (as well as every other object), but if the aspect ratio is less than the AR of the background image I want the image to be cut off at the edges.

Further, I have a game object I need to always be at the corner of the screen. I'm guessing I should use a script to determine the width of the screen and place it a few coordinates up and right of that on start?

The game is only in landscape mode if that matters. How do I go about this? I previously had the background as a plane with an image on it but it didn't take up the whole screen and I think it might not be the right thing to do? Maybe use a quad?

How do I test to make sure that this works? I only have my one android phone to test it on.

Tags : c# unity scripting


Answers 1


For the gameObject to always stay in the corner set it's position to camera.ScreenToWorldPoint(new Vector3(0, 0, -camera.gameobject.transform.position.z)) - new Vector3(yourObjectsizeX / 2, yourObjectsizeY / 2,0) [this to make sure the whole button is visible]

Regarding the scaling, I did a while back such a scale to the background by defining the width and it's maximum size and after scaling on Y respective to the new X. Ex. you have a background of 2048 X 1536 and background size 20.48 X 15.36. For x= 1024 you'll have y=768 hence your background will scale to 10.24 X 7.68.

Hope this helps

Ilona Hari
Ilona Hari
February 19, 2015 17:30 PM

Related Questions


Updated April 23, 2015 21:05 PM

Updated April 08, 2015 18:05 PM

Updated April 14, 2015 20:05 PM

Updated May 17, 2015 21:05 PM

Updated June 07, 2015 22:05 PM