Center GUI content

Hi,

I’m trying to put up some text in the middle of the screen. So in an OnGUI function I’m using GUI.Label(Rect … ; and I’m trying to use the screen class to determin the center X/Y position.

I’ve tried both Screen.width and Screen.currentResolution.width, but both return 1920 (when its should be 1024). And I’ve tried both Screen.height and Screen.currentResolution.height, but both return 20 (when it should be 768). Am I missing something?

Cheers.

This post should maybe be in UnityGUI section…

Your problem sound peculiar. If I want to center a label I do:

GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 10, 200, 20);
//Screen.width / 2 - wanted width
//Screen.height / 2 - wanted height

But if you get those outputs something else must be wrong…

Can you post the relevant parts of the script you are using?

I am also getting different results when using Screen.width or Screen.currentResolution.width. When I build the player I get strange behaviours. Should that values be the same on full screen?