- Home /
Duplicate Question
screen size problem
hello , i want to make this health bar Compatible with any screen size width & height for android .. How i can make this !! I,m still new in unity , thanks all
function OnGUI()
{
var HealthBox=CurHealth/FullHealth*400;
GUI.Box(new Rect(70,20,HealthBox,15),"",greenBox);
GUI.Box(new Rect(70+HealthBox,20,400-HealthBox,15),"",redBox);
}
This question have been asked probably 150 times...
Answer by xandermacleod · Jun 29, 2014 at 07:34 PM
rather than using set-values like 70, 20, 15 and 400 you need to use values that relate to Screen.width and Screen.height.
you will also need to decide what can be your minimum and maximum screen sizes before the screen size does not influence the gui (i.e. if the screen is too small to read the text inside you might need to keep the gui take up more screen space than it normally would to accommodate your text).
Follow this Question
Related Questions
Screen width and height, how to bypass?! 1 Answer
Changing height of camera based on device aspect ratio. How? 0 Answers
Input.acceleration with Screen.width 1 Answer
behavior of Screen object differs in Unity 3 1 Answer
Object resolution 0 Answers