How to fit multiple resolutions while UI moves into canvas dynamically?

I try to explain this well, it drives me crazy.

Generally we design UI to fit multiple resolutions by using anchors and I do it well.

But problem is, my UI is placed out of the canvas, and when game starts, I modify its position to let it appears.

For example, the resolution is 1080*1920, and I just write UI.position = new Vector3(540, 960, 0) , then it will be placed to the position I want, it looks perfect.

However when the resolution turns to 1536*2084 or any other different, the “new Vector3(540, 960, 0)” is no longer the right place that it should be! So my question is how can I get the right position no matter what resolution is?

Hi there,

From your question, i can see that you want to take the exact center of the screen.

You can achieve this by:

new Vector3(Screen.width/2, Screen.height/2, 0);

Accessing the width and height of the Screen, will get you the resolution. Simply divide that by 2.

Hope it helps.