x


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, 2011 at 03:52 AM

Devlus gravatar image

Devlus
62 17 14 23

(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, 2011 at 03:57 AM

sneftel gravatar image

sneftel
1.9k 16 19 39

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

May 01, 2011 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, 2011 at 05:31 AM

GlennHeckman gravatar image

GlennHeckman
395 20 27 33

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, 2011 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, 2013 at 07:36 PM

extrime gravatar image

extrime
0 10 11 14

(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:

x5011
x4327
x521

asked: Apr 30, 2011 at 03:52 AM

Seen: 3420 times

Last Updated: Feb 10, 2013 at 07:36 PM