Resolution Independent GUITexture?

Hey, so I’m making a game both for PC and iOS, (iPad, iPhone, iPod), but my problem is that I positioned Penelope’s tutorial joysticks and they look correct on the unity editor, but once I export to my iPad with Retina it all goes very small and the joysticks end up in the lower left corner. They are still usable though. So how can I position a guitexture in the Unity Editor and make it to the same scale and position when exported to a different resolution such as iPad 3?

You will need to code the size manually based on the Screen.width and Screen.height values. This way you will have the same relative size no matter what the end resolution is.

public var t:GUITexture;

function Start()
{
    t.pixelInset.width =0.1*Screen.width;
    t.pixelInset.height=0.1*Screen.width;
}

I use Screen.width for both so the texture is a perfect square. This will make the texture 1/10 the size of screen width.

  1. GUITexture’s position in XY is screen-relative position. texture position will be ‘sticked’ to this point. for example, if you want to show a texture in screen’s center, use X=0.5 Y=0.5. if in corner, X=0 or 1 Y=0 or 1 depends on which corner.
  2. GUITexture’s size in pixels should be the same in any screen, so texture’s real size depends on pixel’s size. on iDevices with higher resolution pixels are smaller and your texture will looks smaller. cause almost all iDevices have small pixel size, just increase texture scale for iDevices build. Also, you could scale GUITexture to screen size with fixed divisor

Using Screen.width is not future-proof. Instead, use Screen.dpi to detect the actual pixel density of the display.

Attach this script to any GUITextures you use in your game.

void Start () {

		//check for retina display
		bool isRetina = Screen.dpi >= 150;
		if (isRetina) {
			// double pixelInset if we're using retina
			Rect pi = guiTexture.pixelInset;
			guiTexture.pixelInset = new Rect(pi.x*2, pi.y*2, pi.width*2, pi.height*2);
		}

	}