- Home /
Change GUITexture width
I have a GUITexture with a script attached (IN C##) and all I want to know is what code can I use to have the width of my guitexture equal to a variable such as (Width= target.health) something of that sort! Thanks!
could u explain more of the question? u mean u want to create new script to access the width of the GUITexture?
if that so, i have one in Javascript, maybe u want me to put it here?
Answer by woodoo · Jan 14, 2014 at 02:23 PM
You can change its scale X.
To change it, just follow up this snippet:
GUITexture theTexture = new GUITexture();
Vector3 textureScale = theTexture.transform.localScale();
textureScale.x = target.health;
theTexture.transform.localScale = textureScale;
Considering that your scale was previously 1f 1f 1f, your width will be scaled as the value of target.health
Hope it is what you need.
Edit: if your target.health
value is big, you can code some math to get a cool value from target.health
to make it fit well with your texture scale.
Your answer
Follow this Question
Related Questions
Texture height based on it width. 1 Answer
My GUITexture shrinks on both sides 0 Answers
NGUI Texture front of Sprite 0 Answers
How to Get Image edge size 2D?? 1 Answer
UI Button Sizing unit 0 Answers