- Home /
GUI text not updateing
I'm trying to do a health system via GUItext heres the code I have for the GUIText its in java script but here
var score = 0;
function Update () {
var text = "Health: ";
guiText.text = text + score.ToString();
}
and heres the code I have for when the zombie collides with the player
var score = 1;
var GUIhealth : GUIText;
function OnTriggerEnter( other : Collider )
{
if (other.tag == "zom")
{
score++;
GUIhealth.text = score.ToString();
}
}
but the text isnt updateing when the zombie hits the player the gui text is named GUIhealth but it isnt working:/ what am I doing wrong?
Answer by aldonaletto · Jun 27, 2011 at 03:55 AM
You are doing twice the job: first in the GUIText script - where you do it the wrong way, since its score variable is never modified by the player's health - and in the player's script, where it should work. Delete the Update function from the GUI script (or the entire script, if there's nothing else in it).
Your answer
Follow this Question
Related Questions
Show score when enemy is destroyed C# 1 Answer
I used a GUIText to show the score in my game but it doesn't show my true results 0 Answers
Player Attacking Enemy Issue 0 Answers
Rigidbody Collider Hero health does not drain when touched by an enemy rigidbody collider. 2 Answers
collison scoring 1 Answer