- Home /
GUI for different resolutions.
Hi. How do you create GUI for different resolutions? First of all, I'm developing for mobile and I don't want to use OnGui function. I just want to create textures seperately and use them as buttons. However, positioning textures using Screen.width and Screen.height variables seems ok, but I can't say the same for gui text. Since gui text has pixelOffset variable instead of pixelInset unlike gui texture. There has to be a solution for that. I'd like to hear your opinions. Thanks!
If you have a gomeobject with guiText, you can position it the same way you position your other GUI elements. I recommend using sprites for buttons though. That way, you can have all your GUI stuff on a sprite sheet to reduce draw calls.
I agree but what about something like game score for instance? You can't just use sprites for that.
Answer by Nick4 · Mar 23, 2014 at 03:49 PM
I found a way to calculate the ratio for different resolutions in case anyone needs it :
private const float defaultSize = 64f;
private const float defaultRes = 1624; // 1024 + 600 , Default resolution added together
// defaultSize is the value that fits in defaultRes in my case
void Start()
{
this.guiText.anchor = TextAnchor.MiddleCenter; // Optional
this.guiText.fontSize = (int)(((Screen.height + Screen.width) * defaultSize) / defaultRes);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613140808im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player Screen Resolution 2 Answers
Fit GUI to various android screen resolutions and densities 6 Answers
Fixed to the screen GUI ? 1 Answer
NOT auto resizing GUI, keeping GUI always the same aspect ratio 0 Answers
GUI adapting to screen resolution? 3 Answers