Calling a variable

Hi this may sound like a very dumb question but I am trying to get the explosion to be made at the player location but only when the health reaches 0, here isi the script.

var explosion : GameObject;
var playerHealth = 100;
var damage = 10;

function OnCollisionEnter(collision : Collision)
{
	var contact : ContactPoint = collision.contacts[0];
	var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
    var playerDead = Instantiate (explosion, contact.point, rotation);

   if(collision.gameObject.tag=="objectA" || collision.gameObject.tag=="objectB" || collision.gameObject.tag=="objectC") 
   {
     	playerHealth -= damage;
   }
}

function Update()
{
	if(playerHealth <= 0)
	{
                //want to call the playerDead variable here if possible
		Destroy(gameObject);
	}
}

Thank you

You just need to rearrange things a little bit.

In your OnCollision-

if(collision.gameObject.tag=="objectA" || collision.gameObject.tag=="objectB" || collision.gameObject.tag=="objectC") 
{
     playerHealth -= damage;
    
     if(playerHealth <= 0)
     {
         // Instantiate the explosion, delete the object
     }
}

Then just get rid of the thing in Update (since it is now unnecessary)

Try Instantiting the explosion in the if block, not inside the OnCollisionEnter function