- Home /
The problem is solved
Shrink GUI
Hello, guys. Now I'm facing with another issue. I made texture for the player's health. I used OnGUI ()
to make it. When the health drops, I reduce the width of the GUI. However, when it is reduces, it also affects the height. So how can I solve that? Thank you!
Here is my code :
var healthBar : Texture2D;
var health : int = 100;
function OnGUI ( ) {
var screenPos : Vector3 = camera.main.WorldToScreenPoint (transform.position);
GUI.Label (Rect (screenPos.x, Screen.height - screenPos.y, health / 2, 100), healthBar);
}
Answer by syclamoth · Sep 30, 2011 at 02:24 PM
Textures getting stretched/squashed is a setting you have to set up in the GUIStyle. Try defining a custom GUIStyle for your health-bars, and then tick 'stretchHeight' to true. By default it doesn't like messing with your texture sizes, but for something like a health bar, it's obviously desired behaviour.
I have played around with all of those in GUIStyle. But the problem still remain.
Well, I just solve the problem. I make a GUI.Box. When I scale it in width, it doesn't affect the height. So I use it and put a picture in it. And the problem is solved. And thanks for all your help. I appreciate it. :)
Follow this Question
Related Questions
Working health script? 2 Answers
problem with gui 2 Answers
Some code works in OnGUI(), some doesn't. 1 Answer
rect.width gets set to 0 for unknown reason 1 Answer
Scrollbar Thumb Scaling 0 Answers