Home > Net >  Scale Player Size according to the screen size in Unity
Scale Player Size according to the screen size in Unity

Time:08-26

I have an issue with different resolutions.

Everything perfectly works on 1920x1080 however when i set it to tablet size like 10x10 aspect ratio 'Player' isn't resizing.

My platforms created under Canvas due to scalement and correct positioning. However my player created outside of the canvas.

Should i create my character under canvas or should i create my platforms outside of it? Currently I am not sure how to solve the issue.

1920x1080

10x10 aspect ratio

CodePudding user response:

Since player is created outside the canvas, there's no way for canvas to affect it (also player is probably using SpriteRenderer not Image component).

One way would be to put player as Image inside a canvas, but to be honest, canavs is created for UI, not gameplay. Putting all gameplay into UI might (and probably will) create a lot of issues. I'm already surprised that player and platforms interact in your game well as they use different systems.

What you probably want to do is to put all gameplay elements (character, platforms, projectiles, etc.) outside the canvas as sprite renderers and leave canvas for what it's meant to be (UI, maybe backgrounds).

Then, you might come across a problem, where on different resolutions, you have smaller or larger area of gameplay. Your options will be to: live with that, create system that restricts gameplay and fills empty space with background or black bars, or something in between (which is for eg. let vertical gameplay area be different, but horizontal the same).

Here's idea how you could achieve it: https://forum.unity.com/threads/maintain-the-game-content-area-on-different-types-of-screen-sizes.905384/

  • Related