x


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

more ▼

asked Apr 29 '13 at 11:44 AM

laurienvictoria gravatar image

laurienvictoria
141 16 35 42

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 29 '13 at 11:47 AM

Graham Dunnett gravatar image

Graham Dunnett ♦♦
18.5k 12 23 83

Thanks - I'll give that a go!

Apr 29 '13 at 08:39 PM laurienvictoria
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2986
x1183
x550
x44

asked: Apr 29 '13 at 11:44 AM

Seen: 299 times

Last Updated: Apr 29 '13 at 08:39 PM