- Home /
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?
Answer by OperationDogBird · Aug 18, 2012 at 10:40 PM
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.
Answer by ScroodgeM · Aug 18, 2012 at 10:36 PM
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.
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
Answer by pixel_fiend · Jun 30, 2014 at 07:11 PM
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);
}
}
Your answer
Follow this Question
Related Questions
Setting resolutions for iPad and iPhone 0 Answers
How do I set up my editor to "ipadview" 0 Answers
How do I make the size of GUI objects the same across all resolutions? 3 Answers
Dynamically choosing a high resolution texture at runtime on iOS devices 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers