Score script player dissapearing

Hi there could someone please let me know what is wrong with this script. When i start the game my character just dissapears also my score automaticly starts at 5 and when i have it attached to the colectable object and i collide with more than 1 it never adds more score

var addpoints = 0000; var healthsound : AudioClip;

function OnTriggerEnter (other : Collider) {

if (other.gameObject.tag == "collect"); addpoints += 0005; Debug.Log ("Score = " + addpoints); Destroy(gameObject); AudioSource.PlayClipAtPoint(healthsound, transform.position);

}

Can you see the character in the scene view or the camera view. When you press play only the camera matters. The script you posted has nothing to do with your character disappearing.

First, a cleaned up formatting of your code...

var addpoints = 0000;
var healthsound : AudioClip;

function OnTriggerEnter (other : Collider) {
    if (other.gameObject.tag == "collect");
    addpoints += 0005;
    Debug.Log ("Score = " + addpoints);
    Destroy(gameObject);
    AudioSource.PlayClipAtPoint(healthsound, transform.position);
}

I'm not certain why the OnTriggerEnter() is going off right away (some other trigger near the player) but your oddities come from a pair of bugs within it.

Your 'if' statement is followed by a semi-colon rather than a open brace (thus immediately ending the conditional block) so the entire function will be called regardless of what trigger it collides with. Secondly your Destroy() call is actually destroying the object that the script is attached to, i.e. the player. Since your have not qualified the gameObject variable your are passing to it, you are actually passing this.gameObject.

What you want is...

function OnTriggerEnter (other : Collider) {
    if (other.gameObject.tag == "collect") {
        addpoints += 0005;
        Debug.Log ("Score = " + addpoints);
        Destroy(other.gameObject);
        AudioSource.PlayClipAtPoint(healthsound, transform.position);
    }
}

Now it should only add points when a "collect" object collides with it and it will no longer destroy the player object.

Answered Thanks loramaru