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;
}
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.
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.