GUI position according to screen resolution

Hi,

I have multiple GUIs in my game. They should be at different corners/sides of the screen. But the GUI positions are calculated from the center. So they end up in different positions in different screen resolutions.

How can I put them in the correct positions, for all resolutions?

What you probably need to do is get your Screen width and height and do a little math to determine the scaled placement of them. You might also need to scale all of your gui elements by that same amount, so check it out.

public float targetWidth;
public float targetHeight;

private Vector2 guiScaler;

void Awake()
{
    guiScaler = new Vector2(targetWidth / Screen.width, targetHeight / Screen.height);
}

Then you can use guiScaler.x and guiScaler.y to scale your gui elements appropriately.

Note: I may have gotten the division backwards… :slight_smile: