I am trying to make a life counter.
I have used the premade 3rd person controller that comes with unity and named it “PersonController”.
I have attached the following script (called LifeCounterPlayer) to it:
static var lifeCounter : int = 3;
function OnCollisionEnter (otherObject : Collision) {
if (otherObject.gameObject.tag == “enemy”){
lifeCounter --;
}
}
I have then created a GuiText called “GuiLifeCounter”. I am not sure how to gain access to the variable “lifeCounter” and display it in this guiText. I have tried the following:
function Update () {
var playersLife = PersonController.GetComponent(“lifeCounter”);
guiText.text = "Players Life = " + playersLife;
}
Next I will try and have a guiTexture that displays the lives. eg - one heart in the top left corner for each life the player has. If someone has seen a tutorial video or some other type of tutorial that will help, I would really apprieciate it.
Thanks for the help.