Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Sign in to follow this  
Logystone

UI Canvas fit to all screen resolutions [Android]

Recommended Posts

Hello everyone,

I think most of you guys who develop android games faced errors with canvas scaling with screen sizes, Like UI elements sometimes out of screen

Well, First of all i tried to set a fixed resolution to all screen devices, but some devices uses more memory that it's expected to use which cause a lot of  lags,

Please login or register to see this code.

After a hard work of research 🤣😂  i made this script  

Please login or register to see this code.

The resolution the UI layout is designed for. If the screen resolution is larger, the UI will be scaled up, and if it’s smaller, the UI will be scaled down.

i tested it on 4 devices with different screen resolutions and it worked,

------

Tips :

-Create a new GameObject in Hierarchy .

-Name it what ever you want.

-Create a new script like : "CanvasManager."

-Drag the code above in the script

-put the script in the GameObject

-Drag CanvasScaler to the GameObject which contains the script

-Make sure the CanvasScaler :

1] UI Scale Mode : Scale with screen size 

2] Reference Resolution : as you want but what i tested it was on (1440x2880)

3] Screen Match Mode : Match Width Or Height and make sure it's set to : 1 (width(0)------------(0.5)-----------Height(1))

------------

It wont work in the Editor(elements collide with each other), test it on android device and it will work fine

------------

if anyone have better than this please post it here :) 

Thank you so much!

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...