enemy explode

i want my enemy to destroy and explode but it wont

var life = 0;
var explosion : GameObject;
 
function OnCollisionEnter(boom : Collision) {
    if (explosion.active == false)
        if(boom.gameObject.tag == "bullet")
        {
           life +=1;
           if(life == 30)
               Destroy(gameObject);
           explosion.SetActiveRecursively(true);
        }
}

Ok so all i need is brackets on if

       {if}(life == 30)

You forgot the braces ‘{’ and ‘}’ before line 10 and after 11 respectively, i.e, after the if(life==30) block. Your code should look like this:

var life = 0;
var explosion : GameObject;
 
function OnCollisionEnter(boom : Collision) 
{
if (explosion.active == false)
    if(boom.gameObject.tag == "bullet")
    {
    life +=1;
    if(life == 30)
        {
        Destroy(gameObject);
        explosion.SetActiveRecursively(true);
        }
    }
}

The problem, as-is, is that the first bullet hit will “always” cause an explosion, regardless of whether life = 30 or not.