- Home /
how would you make guiTexture.pixcelInset.width a variable?
Hi im having trouble with my game respawn I want the respawn sequence to be triggered when the guiTexture.pixcelInset.width is <0 but i keep getting this error:
Assets/script/HealthControl.js(1,22): BCE0018: The name 'GUITexture.pixelInset.width' does not denote a valid type ('not found').
Here is my code:
//goes on healthbar
static var HBWidth : GUITexture.pixelInset.width;
function Update ()
{
if(Interaction.gotHit)
guiTexture.pixelInset.width -=10;
}
function LateUpdate()
{
Interaction.gotHit = false;
}
//goes on player1
static var gotHit = false;
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "enemyFire")
{
gotHit = true;
}
else
{
if(HBWidth<0)
{
dead = true;
}
}
}
please help thanks
in hindsight i shall add the whole code including all the variables:
HealthControl //goes on healthbar static var HBWidth : GUITexture.pixelInset.width;
function Start () {
}
function Update () { if(Interaction.gotHit) guiTexture.pixelInset.width -=10;
} function LateUpdate() { Interaction.gotHit = false; }
Interaction //goes on player1 var bullitPrefab :Transform;
static var gotHit = false; static var dead = false;
function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "enemyFire") { gotHit = true; } else { if(HBWidth<0) { dead = true; } }
}
//player 1 shoot function Update() { if(Input.GetButtonDown("Fire1")) { var bullit =Instantiate(bullitPrefab, GameObject.Find("$$anonymous$$ain Camera").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2700);
}
}
Answer by Berenger · May 16, 2012 at 03:06 PM
You are trying to access pixelInset as if it was a static var but it is not, hence the compiler output. You need the reference of the component to access it. You have the property guiTexture or the function GetComponent for that.
However, that's still won't work. Float isn't a class and HBWidth will not be a reference, which means it will remains constant when pixelInset changes.
You have many ways to do this. you could call a function returning a bool in player1's OnTriggerEnter (but you need a ref of healthbar), or do the test inside healthBar and tell the player if he is dead, but you'd need the ref of the player.
cool give me a $$anonymous$$ute to absorb that and make the changes then see how it goes thanks
I have tried to follow what you have said and i have altered my code like this:
//HealthControl
var healthWidth = GetComponent(guiTexture.pixelInset.width);
function Update () { if(Interaction.gotHit) guiTexture.pixelInset.width -=30;
else { healthWidth : <0; dead = true;
}
Interaction.dead = true;
} function LateUpdate() { Interaction.gotHit = false;
if(Interaction.dead)
{
Application.LoadLevel(0);
dead = false;
}
}
but now i keep getting this error: Assets/script/HealthControl.js(15,9): BCE0043: Unexpected token: healthWidth.
can anyone please help thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613071545im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Dynamic Health Bar in unity 4.6 0 Answers
Help With Enemy Health bars 3 Answers
Issue with GUITexture width. 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer