Unity3D: Manage GUI elements for any aspect ratios (2D 3D)

23-Aug-20131 Min Read

I do know that lots of discussions have happened on this topic and most of them are resolved, Recently, I've came across a large game project, which had lots of GUI elements to be drawn at on screen on different times. I somehow managed to draw it, but there were a big issue when switch the game to different aspect ratios. And I've found out a real simple solution to solve this problem and I'd like to share this simple idea so that it may help some people. This method will work for almost all platform. No matter what the player's screen aspect ratios are:

Step 1 : Divide your screen as 10x10 grids (Make a rough sketch or something like that to figure out where do you want to put your GUI elements on screen)

note

I'm not good at MS Paint 😅

ASPECT

And write your script as follows

Resizable screen#

If you're having a Resizable screen, the Above code will only work according to the Startup screen size. To solve this issue you could do a small edit in the above script.

note

The second method will calculate dx,dy value on each frame of GUI. So I recommend to use the first method if you're not having a resizable window.