x


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?

more ▼

asked Jun 27 '11 at 03:49 AM

twoface262 gravatar image

twoface262
129 41 53 56

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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).

more ▼

answered Jun 27 '11 at 03:55 AM

aldonaletto gravatar image

aldonaletto
42.5k 16 43 202

I got it thanks man.

Jun 27 '11 at 04:07 AM twoface262
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1765
x394
x319
x280

asked: Jun 27 '11 at 03:49 AM

Seen: 1514 times

Last Updated: Jun 27 '11 at 04:07 AM