i've looked through questions already but i cant seems to find a specific answer/script to my problem. im making a ball rolling game which destroys objects in turn giving you a score. i have 2 scripts at the min:
static var score : float = 0;
function Update () {
guiText.text = "Score : " + score;
}
this shows "score:" on the screen and my other script is:
function OnCollisionEnter ( collision : Collision){
if (collision.gameObject.tag == "DestructibleObject")
KeepScore.score++;
}
which is attatched to my player (rolling ball) and updates the "score:" by 1 everytime i hit an object named "DestructibleObject". the problem is that the score keeps increasing, im wanting to limit the score to 1 for each object. it would be even better if anyone can tell me how to destroy the object at the same time. i added the line:
Destroy (collision.gameObject);
so the script looks like:
function OnCollisionEnter ( collision : Collision){
if (collision.gameObject.tag == "DestructibleObject")
KeepScore.score++;
Destroy (collision.gameObject);
}
but when i load the level the terrain is getting destroyed (i think when my ball thouches it to start with). if i remove the keepScore.score++; line i can go round the level fine (it doesn't get destroyed) and when i hit an object it is destroyed. when the 2 lines of script are together it just doesn't want to work : /
any help is highly appreciated
thanks.