GUI scaling on mobile

Hello. I’m using a standard Unity GUI. I am trying to scale it to make my game playable on devices with different resolution. The problem is I can not figure out how to scale GUI properly according to the DPI of device’s screen.

I tried this method Unity3D: script to automatically scale gui elements on high dpi devices (like iPhone 4 or iPad 3rd Generation). · GitHub but for some reason it doesn’t work for me on my mobile phone but on PC it does work (but if I change the resolution at runtime it stops working).

I am attaching two screenshots. The first one is from my mobile phone and the second is from my PC!

What I’ve always done is to use relative sizes in my GUI. Instead of saying this box is 50px wide, I say this box is 1.2% of Screen.Width or something similar. That way, when the screen size changes, the box changes too. Although, this is quite a painful way to do things…I usually start with my GUI laid out exactly the way I want it, absolutely, then go through and convert it to relative (by dividing the absolute numbers by the current Screen.Width)

Perhaps you could use Screen.dpi to get a better result though.