Score keeping script

I'm sorry to post another score keeping script question, but I honestly don't know why my script isn't functioning. I am try to get my GUIText score counter to increase by five every time the the game object bullet(Clone) collides with anythings... very simple, and for some reason that i am not aware of, it doesn't not work, meaning that the score counter stays at 0. Thanks in Advance

    var score : int = 0;
//when a bullet collides with anything, i want to add five to the score.
function OnCollisionEnter(theCollision : Collision) {
    if (theCollision.gameObject.name == "bullet(Clone)"){
    score += 5;
//manages the guitext that displays the score
function Update() {
    guiText.text = "Score: "+score;
more ▼

asked Apr 30 '11 at 03:52 AM

Devlus gravatar image

62 6 6 15

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

3 answers: sort voted first

I seem to recall that there's a space there... that is, the name should be "bullet (Clone)", not "bullet(Clone)". A considerably more robust way to do that, though, would be to set the bullet prefab's tag to something like "bullet", and then check theCollision.gameObject.tag instead. That's guaranteed not to be renamed.

more ▼

answered Apr 30 '11 at 03:57 AM

sneftel gravatar image

1.9k 7 10 22

I am sorry to say that this isn't the solution, there isn't a space

May 01 '11 at 01:52 PM Devlus
(comments are locked)
10|3000 characters needed characters left

If the spacing in the name wasn't the issue, try making your score variable private so that the properties panel doesn't retain control over the value.

private var score:int = 0;

Or if the score variable must remain public for use in other scripts, you can put the @HideInInspector on the line above your variable declaration to keep it hidden.

more ▼

answered Apr 30 '11 at 05:31 AM

GlennHeckman gravatar image

400 7 10 19

The inspector doesn't "retain control" over component properties at runtime. It sets them to their initial values when the level is loaded, and can be used in the editor to view and modify them at runtime, but it doesn't prevent scripts from changing them, and it doesn't revert those changes.

Apr 30 '11 at 02:53 PM sneftel
(comments are locked)
10|3000 characters needed characters left

I have that problem to.If you find how to fix it pls tell me.

more ▼

answered Feb 10 '13 at 07:36 PM

extrime gravatar image

0 3 5 7

(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



Answers and Comments



asked: Apr 30 '11 at 03:52 AM

Seen: 3009 times

Last Updated: Feb 10 '13 at 07:36 PM