GUI Positioning Problems

How do I make a GUI so that no matter what the screen width is the GUI is always positioned in a certain place? This picture show the problem I’m having. I want the health bar to not overlap the buttons like it does in the smaller resolutions.

alt text

Here is the script:

    var background : Texture2D;
 
    var array : float[];
    
    function OnGUI(){
    
    	GUI.DrawTexture(Rect(Screen.width - Screen.width / 2 - array[0], 10, Screen.width / 10 + array[1], 20), background, ScaleMode.StretchToFill, true, 0);
    
    }

What am I doing wrong?

Thanks.

Looks like you’re mixing percents and pixels. The part Screen.width - Screen.width/2 (which is a long way to write width/2) is mostly saying 50%. I’m guessing array[0] and array[1] are in pixels. Is 1/2-way minus 100 pixels to the right of 30% plus 60 pixels? Who knows?

Easier to think of everything as percents first – lifebar is from 40% to 60%, or 50% +/-array_, which are percents. Then one *Screen.width at the very end. Then, if you really need, look at the final pixel result (say you need at least a 5 pixel border.)_