Why does my counter keep going up after pickup is destroyed?


I have this code which adds 1 to the OBJECTNUMBER every time someone picks up an object. Except sometimes, it adds 2 or 3 to OBJECTNUMBER. I'm not sure why this is as the object is destroyed as soon as my player comes into contact with it. I've followed a tutorial and I've got the same code as that did and it seemed to work fine on the video. Any suggestions?

else if(hit.gameObject.tag == "Helmet1")

        Destroy(hit.gameObject, 0.01);
        OBJECTNUMBER += 1;
        print("you now have" + OBJECTNUMBER);



You have a delay value specified in your Destroy function, of 0.01. This means that your object will be destroyed 0.01 seconds after the object is collected. If your game is running at a fast enough framerate, this can be enough time for another frame or two to elapse before the object is finally destroyed.

You should remove that value completely, so the line looks like this: