How to make a particle effect do damage?
Hi! I was wondering if there is a way to make a particle effect do damage? Like, when a enemy/player enters the particle effect, it will slowly do damage. My particle effect looks like this:
So now the question is, how would I achieve the fire damage? I wrote a extremely basic health script to attach to a cube, so when its health reaches 0, it gets destroyed:
using UnityEngine;
using System.Collections;
public class AI_basichealth : MonoBehaviour {
public float HealthLevel = 100.0f;
public GameObject EnemyObject;
// Use this for initialization
void Start ()
{
if(HealthLevel >= 0)
{
EnemyObject.SetActive(false);
}
}
// Update is called once per frame
void Update () {
}
}
Would I achieve this using particle collision or, what? I don't want a script written for me, but a nudge in the right direction would be greatly appreciated! :D
Thank you so much in advance! - Nikolai
Answer by Owen-Reynolds · Mar 09, 2014 at 09:12 PM
The usual method is -- don't make particles do damage. The particles are just decoration. It's a very old game trick, and you can see in many games where damageArea isn't quite particle area.
Instead, put an invisible collider/trigger in the area, and have it do the damage. Lots of examples of that here.
Answer by N47 · Dec 20, 2019 at 04:15 PM
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html
This might help also.
Checking for particle collisions is new since the answer about adding a trigger, but I still think a trigger is better for damage effects. Particles can randomly go where-ever, and you might make lots of small ones, or fewer big ones for an equally "hot" flame area. The number of particle hits won't be consistent. A sphere trigger is, and is easier to resize, and probably runs faster.
Answer by suIly · Nov 09, 2019 at 07:24 PM
You can set the particle collision by going to the particle system object, setting a tag like "Fireball" for it, and scrolling down to Collision, check it and set it to world. This should work.