|
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.
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.
(comments are locked)
|
|
Looks like you're mixing percents and pixels. The part Easier to think of everything as percents first -- lifebar is from 40% to 60%, or 50% +/-array[i], which are percents. Then one
(comments are locked)
|


In smaller resolutions, it will always overlap, because you are using absolute values in your width coordinate! You should multiply all your values by Screen.width, and then use proportions instead of exact numbers. On the other hand, this only happens on really small screens, so possibly you should do a quick check to see if it would overlap, and then switch between the two methods!