I’m creating a 2D game and I have the following problems :
When I resize the game tab, or use a different resolution, some of the game objects are getting out of the screen, how can I make everything in my game scale to user screen? (size & object positions)
Here is how I want the game to look in every screen :
Only Canvas objects will respect the changing size of the screen. If you want a world space gameobject to be at the right side of the camera, you can convert camera space to world space like this:
That will put it on the right edge, in the middle of the screen vertically. You can either change the 0.5 to something else to give it a different proportion-based position, or add an offset afterwards so that it’s always a specific distance from the center.
The background could go under a Canvas as an Image with an AspectRatioFitter set to Envelope Parent, or you can do the math between the Background width and height, and the camera width and height, and rescale based on the difference.
Thank you for your answer, but is this how it is done in practice? I mean even the cannon (and every game object with a sprite) size must change in function of the screen size, by the way I forgot to mention that this game is for Android phones.
if this is an image then it will go under UI section of unity, and unity has a tool called anchor in the rect transform you can use it to resize and reposition the image based on player view