Keeping track of items

This is a very simple question, but I am new to Unity and JavaScript so I don't know how to do this. In my game, you can pick up items hidden in the levels that will unlock a bonus level when all 10 per level are collected - kind of like the Minikits or Artifacts in the LEGO games Travelers Tales has been making the past few years. I have made the following script:

var collectibles;
function OnTriggerEnter (object : Collider)
{ 
collectibles++;
Destroy (gameObject);
}

However, when I walk through the collectible, nothing happens. Unity then gives this error at the bottom of the screen:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) pickUpCollectible.OnTriggerEnter (UnityEngine.Collider object) (at Assets\Scripts\pickUpCollectible.js:4)

It says the error is on line 4. What am I doing wrong? I know this may sound stupid, but I can't figure it out. Thanks for the help! :)

You never initialised the value of collectibles (should be 0) and, assuming this script is on the collectible object, you're destroying the object that has the collectibles variable on it, so the value will never be saved.

You should declare a numCollectibles variable on a separate GameObject (maybe call it gameManager) and then add to it. For example, in a 'gameStats' script on the gameManager object, you would have:

static var numCollectibles : int = 0;

and then on the collectible gameObject (prefab, presumably):

function OnTriggerEnter (object : Collider)
{
   gameStats.numCollectibles++;
   Destroy(gameObject);
}

I can't test this from where I am, but hopefully it will give you what you're after.