increment issue

Lads,

I’m trying to increment a variable… when the variable reaches 4 I’d like to turn on gravity. I’m not a strong scripter an am having issues. Here’s my code:

var smokePrefab: Transform;
var Sphere: Transform;
var objectDestroyed: int = 0;

Invoke("OnCollisionEnter", 2);

function OnCollisionEnter(collision : Collision) 
{
    if (collision.gameObject.tag == "missile_1")
    {
        Destroy (gameObject);
        Instantiate (smokePrefab, transform.position, transform.rotation);
        Instantiate (Sphere, transform.position, transform.rotation);
        objectDestroyed++ ;
    }
}

{
    if objectDestroyed == 4;
    {
        gameObject.rigidbody.useGravity = true;
    }
}

Any thoughts?..

Thanks.

that should be:

if( objectDestroyed == 4)
{
     gameObject.rigidbody.useGravity = true;
}

And you don’t need the } and { before it I would suggest. Hard to see with how the code is indented.

Hmmm, I’m getting closer, but have now run into another error. The increment ++ goes up to 1 and no further. I added a print command to display the incrementing integer, and it only shows 1, when actually I’m destroying several objects. I was thinking that perhaps I needed to add a void Update()?.. Any thoughts? Here’s my revised code:

var smokePrefab: Transform;
var Sphere: Transform;
var objectDestroyed: int = 0;

Invoke("OnCollisionEnter", 2);
function OnCollisionEnter(collision : Collision) 
{
if (collision.gameObject.tag == "missile_1")
 {
Destroy (gameObject);
Instantiate (smokePrefab, transform.position, transform.rotation);
Instantiate (Sphere, transform.position, transform.rotation);
objectDestroyed++ ;
//print (objectDestroyed);


if( objectDestroyed == 4)
{
     gameObject.rigidbody.useGravity = true;
}
}
}

Thanks!