- Home /
How to create a button for every supported resolution?
I'm using this script:
Resolution[] resolutions = Screen.resolutions;
foreach (Resolution res in resolutions)
{
print(res.width + "x" + res.height);
}
Screen.SetResolution(resolutions[0].width, resolutions[0].height, isFullscreen);
To get all supported screen resolutions. I was wondering how I could create a button (4.6 UI) for every single resolution so when they click on it, it changes the resolution... (duh). How would I exactly do that?
Answer by digzou · Apr 20, 2015 at 09:59 AM
Attach "Canvas Scaler" Component to the Canvas in your scene.
Set UI Scale mode : Scale with Screen Size.
Reference Resolution X : 1080 Y:1920. [Potrait mode. Otherwise if Landscape mode.]
Set Screen Match Mode : Match width or height.
Match : 1.
As for the size of the button, try aligning the each anchor point[small triangles] with the vertices[blue dots] of the rect of your button element. This will resize the button according to your device resolution without doing it via script.
Hope it helps. :)