- Home /
Question by
bpears · Jan 21, 2013 at 01:44 AM ·
javascriptgui
MissingFieldException UnityEngine.GUITexture.width not found?
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");
}
Comment
Answer by sparkzbarca · Jan 21, 2013 at 03:00 AM
Yea you cant use GUITexture.width because it doesn't exist.
GUITexture contains no function or member variable called width.
how do I go about manipulating the guitextures width? I edited to this, but still does not work?
healthBar.pixelInset.width = - healthBarOriginalWidth * (hitPoints/maxHitPoints);
Your answer
Follow this Question
Related Questions
Cropped Label Problem - Big Font - Unity3D 1 Answer
OnGUI and Event.current 2 Answers
How to draw texture in C# without using (new Rect) 1 Answer
GUI opacity. 1 Answer
Coordinates of GUITexture 0 Answers