Score not increasing on Object collision.

I have this script attached to my player, and the object is Tagged correctly “DestructibleObject”. But nothing happens the score never increases it always says Score : 0 when i collide with it.

Can someone take a loot at it see if i missed something, it’s late so my brain shut off at 6pm.

    static var score : float = 0;
    var oneTime : boolean = false;
     
function Update () {
    guiText.text = "Score : " + score;
}
function OnGUI()
    {
    GUI.Label(new Rect(10, 10, 60, 20), "Score: " + score);
}

function OnCollisionEnter ( collision : Collision){
    if(!oneTime){
    if (collision.gameObject.tag == "DestructibleObject"){
    score += 100;
    oneTime = true;
    }
}
}

My suggestion would be a few quick tests to determine where your problem lies. First of all, I’d check if the collision was being detected by adding a debug or print statement at the top of your collision function.

function OnCollisionEnter ( collision : Collision){
    print("Collided");
    if(!oneTime){
        if (collision.gameObject.tag == "DestructibleObject"){
            score += 100;
            oneTime = true;
        }
    }
}

If that is successful, you know the collision is being detected so try putting a debug or print above your score += 100; If this isn’t successful, make sure that both colliding objects have a collider attached. Neither of these colliders can have isTrigger marked as true and at least one must be something other than a mesh collider. Also, at least one of your objects must have a rigidbody component attached.

function OnCollisionEnter ( collision : Collision){
    if(!oneTime){
        if (collision.gameObject.tag == "DestructibleObject"){
            print("Tag detected");
            score += 100;
            oneTime = true;
        }
    }
}

If that is unsuccessful, your tag is probably not set correctly on the object you’re colliding with. Try collision.gameObject.name == ""; instead. If, on the other hand, it is successful, you know something is happening with your static var. I assume somewhere would be setting it to 0. Be very careful with statics unless you understand them fully.

“Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.”

You may try to use OnTriggerEnter(Collider other)? (C# Syntax).
Because as far as I can see you do not need any information about the collision.

Felix