How do i implament health using a particle system?

Im making a game where planets can only take so much asteroid hits and i have a particle system that i want to use for when the plant is low for health. How do i use the particle system for the planets health if an asteroid hits it?

Put a shere collider on the planet and the asteroid. Put the Particle System on the planet’s game object or where ever you want it to be, set it to not emit particles.

Create this script and put it on the planet:

public ParticleSystem particleSystem;

void OnCollisionEnter(Collision col) {
	if (col.gameObject.name == "asteroid") {
		particleSystem.Emit();
	}
}

Set your particle system to the particleSystem variable in the Inspector, when the planet is selected. This also assumes your asteroid is called “asteroid”.

Your planet and your asteroid both need a collider and one of them needs a rigid body. There’s 2 types of collisions the easiest being to implement the OnCollison function on a script attached to your planet. Inside of that you can check if the colliding object is an asteroid and if so, trigger your particle system.