Not sure why I am getting this error…
Am I using .width wrong?
Should I be using pixelinset? sorry, still learning.
@script ExecuteInEditMode()
var hitPoints : int;
var painSound : AudioClip;
var die : AudioClip;
var deadReplacement : Transform;
var mySkin : GUISkin;
var explShake : GameObject;
private var radar : GameObject;
private var maxHitPoints = 100;
var healthBarOriginalWidth = 100;
var healthBar : GUITexture;
var damageTexture : Texture;
private var time : float = 0.0;
private var alpha : float;
private var callFunction : boolean = false;
function Start(){
maxHitPoints = hitPoints;
alpha = 0;
}
function Update(){
if (time > 0){
time -= Time.deltaTime;
}
alpha = time;
}
function PlayerDamage (damage : int) {
if (hitPoints < 0.0)
return;
// Apply damage
hitPoints -= damage;
audio.PlayOneShot(painSound, 1.0 / audio.volume);
time = 2.0;
// Are we dead?
if (hitPoints <= 0.0)
Die();
healthBar.pixelInset.width = - healthBarOriginalWidth * (hitPoints/maxHitPoints);
}
//Picking up MedicKit
function Medic (medic : int){
hitPoints += medic;
if(hitPoints > maxHitPoints)
hitPoints = maxHitPoints;
}
function Die () {
if(callFunction)
return;
callFunction = true;
if (die && deadReplacement)
AudioSource.PlayClipAtPoint(die, transform.position);
// Disable all script behaviours (Essentially deactivating player control)
var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
for (var b in coms) {
var p : MonoBehaviour = b as MonoBehaviour;
if (p)
p.enabled = false;
}
// Disable all renderers
var gos = GetComponentsInChildren(Renderer);
for( var go : Renderer in gos){
go.enabled = false;
}
if(radar != null){
radar = gameObject.FindWithTag("Radar");
radar.gameObject.SetActiveRecursively(false);
}
Instantiate(deadReplacement, transform.position, transform.rotation);
yield WaitForSeconds(4.5);
LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.black, 2.0);
}
function OnGUI () {
GUI.skin = mySkin;
GUI.contentColor = Color.red;
GUI.color = Color(1.0, 1.0, 1.0, alpha); //Color (r,g,b,a)
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), damageTexture);
}
function Exploasion(){
explShake.animation.Play("exploasion");
}