GUI Text from component

I’m trying to sort out my GUI. I’ve got a GUI Text for the lives my character has left and I need it to take it’s number from the “ThirdPersonHealth” script however I can’t seem to work it out. This is what I have so far:

function Update () {
ThirdPersonHealth = GetComponent(ThirdPersonHealth);
	guiText.text = ThirdPersonHealth.var lives.ToString();
}

But it doesn’t like the “var lives” bit at all!

I’ll have to do this with the score and health too but I’ve not even worked out how to get things to add score and health yet!

Any ideas?
Mike

Looks like you have several things wrong here:

  1. you declare (not fully) a variable that is the same name with the class (ThirdPersonHealth)
  2. for some reason you’re adding ‘var lives’ instead of ‘lives’.

Try something like this (this assumes ThirdPersonHealth has a variable named ‘lives’):

function Update () { 
    var healthComp = GetComponent(ThirdPersonHealth); 
    guiText.text = healthComp.lives.ToString(); 
}

Ah, I assumed the variable had to be the same name as the class when bringing in another component. I’ll remember that!

It doesn’t seem to be working, but I’m not certain I’m using the ThirdPersonHealth script properly anyway. There’s no documentation with it so I’m just figuring it all out by dissecting bit by bit, lol!

Thanks!

Mike