- Home /
Error 'ScaleX' is not a member of 'UnityEngine.Texture2D' (help!)
Hello - I want my health bar to decrease proportionately with the amount of player vitality. However I can't seem to link the player's health to the health bar correctly - on using this code which seems to have worked for some people I have been given this error, and I just can't work out how to change it.
Here's the code:
var energyBar : GUIStyle ;
var bgImage : Texture2D;
var fgImage : Texture2D;
static var playerEnergy = 1.0;
var maxHealth : float = 100;
var curHealth : float = 100;
var percentHealth : Number = curHealth / maxHealth;
function Start() {
}
function Update() {
}
function OnGUI () {
GUI.BeginGroup (Rect (10,10,256,32));
GUI.Box (Rect (0,0,256,32), bgImage, energyBar);
GUI.BeginGroup (Rect (0,0,playerEnergy * 256, 32));
GUI.Box (Rect (0,0,256,32), fgImage, energyBar);
GUI.EndGroup ();
GUI.EndGroup ();
}
function updateHealthBar () : void
{
percentHealth = curHealth / maxHealth;
fgImage.ScaleX = percentHealth;
}
If anyone has the time to help, it would be so appreciated.
Thanks in advance, Laurien
Answer by Graham-Dunnett · Apr 29, 2013 at 11:47 AM
The `Texture2D` class does not have a member called ScaleX
. It's just a texture. Adjust the width of the Rect that you use to render this texture.
Your answer
Follow this Question
Related Questions
For some reason when i start the game my players go out of the camera zone ? or they get invisible ? 0 Answers
Bootcamp player is spinning randomly 1 Answer
Making my 2d character's arm follow the mouse, scrpit not working, please help :c 1 Answer
Error building player (unsupported data) 0 Answers
android player error 0 Answers