Search Unity

GUI Label Size and Position Changes With Resolution

Discussion in 'Immediate Mode GUI (IMGUI)' started by PirateMonkey, Sep 14, 2014.

  1. PirateMonkey

    PirateMonkey

    Joined:
    Jun 24, 2014
    Posts:
    28
    Hey all,

    I'm having this very frustrating problem with my HUD GUI interface. I would like to display and textured label in a portion of the screen. The problem is that the position and size get all wonky when I change the screen size/resolution.

    Here is my very simple code:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var missileSymbol : Texture2D;
    4.  
    5. function OnGUI()
    6. {
    7. var symbolWidth : float = Screen.width / 10;
    8. var symbolHeight : float = Screen.width / 10;
    9.  
    10. var xPos : float = Screen.width / 2;
    11. var yPos : float = Screen.height / 2;
    12.  
    13. GUI.Label (Rect(xPos, yPos, symbolWidth, symbolHeight), missileSymbol);
    14. }
    How can I solve this problem with code?

    Thanks!