- Home /
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?
No problem. If an answer solved your question, please mark the answer as such. :)
Answer by mattssonon · Aug 20, 2013 at 05:25 PM
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".
Answer by Yokimato · Aug 20, 2013 at 05:27 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112619im_/https://answers.unity.com/themes/thub/images/avi.jpg)