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);

}

Can you show us your current script?

–

1 Answer

1

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. :)

–