Problem with my Script

Quick question, I have a particle system with a world particle collider on it. I wrote a script so that if those particles touch the item with the script it should remove health and eventually die. It doesn’t do anything. Can someone help me?
Heres the script:

var damage = 1;
var health = 5;

function OnCollisionEnter(Collision){
if(Collision.gameObject.tag == “fire”){
damage -= health;
}
}

function Update(){
if(health == 0){
Destroy(gameObject);
}
}

put some log’s into your code to see where it goes wrong.

var damage = 1;
var health = 5;

function OnCollisionEnter(Collision){
Debug.Log("collision with " +Collision.gameObject.tag);
if(Collision.gameObject.tag == "fire"){
Debug.Log("hit!!");
damage -= health;
}
}

function Update(){
Debug.Log("health = " +health);
if(health == 0){
Destroy(gameObject);
}
}

now if you see hit!! in the console when you hit a fire object then there is probably something wrong in the update function.
if it isn’t then you should look at the “collision with” log’s

The only other suggestion I can make is regarding your (health == 0) check. If your damage is a value other than 1, then you may skip over this entirely. Consider if the damage is 2:

Health = 5
Hit!
Health = 3
Hit!
Health = 1
Hit!
Health = -1

Notice it skips past 0 in this case, it never actually equals zero. So instead, check for (health <= 0)

EDIT: Just to clarify, I don’t think this is the problem you’re currently facing, but it would undoubtedly be one you’d face later on.

The World Particle Collider doesn’t use OnCollisionEnter for its collisions, it uses OnParticleCollision(hit : GameObject). Add in function OnParticleCollision() and you should be set!

It still doesn’t work.

Is nothing coming out with your Debug.Logs? Did you verify that all the objects colliding have colliders?