Counter problem

Hi. I am a beginner in Unity. I am doing the Challenge 03 (Unity 3D Student - 3d Modelling) and got some problems. I have written a script.

var Counter :int =0;
function Update(){
var fwd =transform.forward*100;
rigidbody.AddForce(fwd);
}
function OnCollisionEnter(theCollision:Collision){
if (theCollision.gameObject.name=="smalltarget" ){
Destroy(theCollision.gameObject);
Destroy(gameObject);
   //not Destroy(gameObject.Find("smalltarget");
   Counter++;
   //tried also Counter+=1

Debug.Log("smalltarget destroyed");
}
Debug.Log(Counter);
if (Counter >=3){
Debug.Log("now scene must be loaded");
}
}

The problem is that the Counter number remains 1 in Debug.Log and it is not rising. What should I do? Could you help me please?

  • What is the Log printing out?
  • Which GameObject/prefab is this script attached to?
  • Line 9: Destroy(gameObject); seems to be destroying the current object and by extension this instance of the script, if any other instances of this script exist on other gameObjects in your scene they will have their own counter variable, that will hold independent values.